0

我在http://www.zillow.com/webservice/GetSearchResults.htm 访问Zillow 的 seach API,并使用 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)
4

1 回答 1

0

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

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

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

于 2014-04-23T19:56:10.363 回答