【问题标题】:Zillow API parse the JSON Ruby on Rails 4Zillow API 解析 JSON Ruby on Rails 4
【发布时间】:2014-04-23 15:50:04
【问题描述】:

我在http://www.zillow.com/webservice/GetSearchResults.htm 访问 Zillow 的搜索 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)

【问题讨论】:

    标签: ruby-on-rails json api parsing zillow


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2010-12-22
      • 1970-01-01
      相关资源
      最近更新 更多