Zillow API parse the JSON Ruby on Rails 4



我正在访问Zillow的seach APIhttp://www.zillow.com/webservice/GetSearchResults.htm我已经使用HTTParty将代码转换为JSON。如何提取特定值,例如"地址"或"城市"?

我在尝试类似response.price的东西,但那是错误的。然后我尝试了response[0]response['city'],诸如此类的东西。。。

[1] pry(Zillow)> response
=> {"searchresults"=>
  {"request"=>{"address"=>"7 Clive St UNIT 2", "citystatezip"=>"02130"},
   "message"=>{"text"=>"Request successfully processed", "code"=>"0"},
   "response"=>
    {"results"=>
      {"result"=>
        {"zpid"=>"120921393",
         "links"=>
          {"homedetails"=>
            "http://www.zillow.com/homedetails/7-Clive-St-UNIT-2-Jamaica-Plain-M
           "graphsanddata"=>
            "http://www.zillow.com/homedetails/7-Clive-St-UNIT-2-Jamaica-Plain-M
           "mapthishome"=>"http://www.zillow.com/homes/120921393_zpid/",
           "comparables"=>"http://www.zillow.com/homes/comps/120921393_zpid/"},
         "address"=>
          {"street"=>"7 Clive St UNIT 2",
           "zipcode"=>"02130",
           "city"=>"Jamaica Plain",
           "state"=>"MA",
           "latitude"=>"42.317562",
           "longitude"=>"-71.108245"},
         "zestimate"=>
          {"amount"=>{"__content__"=>"500537", "currency"=>"USD"},
           "last_updated"=>"04/20/2014",
           "oneWeekChange"=>{"deprecated"=>"true"},
           "valueChange"=>nil,
           "valuationRange"=>
            {"low"=>{"__content__"=>"475510", "currency"=>"USD"},
             "high"=>{"__content__"=>"525564", "currency"=>"USD"}},
           "percentile"=>"0"},
         "localRealEstate"=>
          {"region"=>
            {"links"=>
              {"overview"=>
                "http://www.zillow.com/local-info/MA-Boston/Jamaica-Plain/r_1547
               "forSaleByOwner"=>
                "http://www.zillow.com/jamaica-plain-boston-ma/fsbo/",
               "forSale"=>"http://www.zillow.com/jamaica-plain-boston-ma/"},
             "id"=>"154795",
             "type"=>"neighborhood",
             "name"=>"Jamaica Plain"}}}}},
   "schemaLocation"=>
    "http://www.zillow.com/static/xsd/SearchResults.xsd http://www.zillowstatic.
(END)

太好了,我想通了。这里有一个例子:

response["searchresults"]["response"]["results"]["result"]["zestimate"]["amount"]["__content__"]

每组方括号都在访问嵌套的内部。希望他们不会更改格式!

最新更新