0
HTTPartyのAPI結果にアクセスしようとしていますが、どうしたらいいかわかりません...次のようなzillowという変数に結果を格納しました:httappy APIにアクセスするとrubyになります
=> {"searchresults"=>
{"request"=>{"address"=>"49 Alpine Way", "citystatezip"=>"28805"},
"message"=>{"text"=>"Request successfully processed", "code"=>"0"},
"response"=>
{"results"=>
{"result"=>
{"zpid"=>"5628657",
"links"=>
{"homedetails"=>"http://www.zillow.com/homedetails/49-Alpine-Way-Asheville-NC-28805/5628657_zpid/",
"graphsanddata"=>"http://www.zillow.com/homedetails/49-Alpine-Way-Asheville-NC-28805/5628657_zpid/#charts-and-data",
"mapthishome"=>"http://www.zillow.com/homes/5628657_zpid/",
"comparables"=>"http://www.zillow.com/homes/comps/5628657_zpid/"},
"address"=>
{"street"=>"49 Alpine Way",
"zipcode"=>"28805",
"city"=>"Asheville",
私は "zpid"にアクセスしようとしていますが、応答としてnilを取得し続けます。私は以下を試しました:
[107] pry(main)> zillow["searchresults"]["zpid"]
=> nil
[108] pry(main)> zillow["zpid"]
=> nil
[109] pry(main)> zillow["searchresults"]["results"]["zpid"]
NoMethodError: undefined method `[]' for nil:NilClass
from (pry):100:in `<main>'
[110] pry(main)> zillow.find["zpid"]
NoMethodError: undefined method `[]' for #<Enumerator:0x0000000323b3f8>
from (pry):101:in `<main>'
[111] pry(main)> zillow.get["zpid"]
NoMethodError: undefined method `get' for #<HTTParty::Response:0x00000003adb0f8>
from /home/pjw/.rvm/gems/ruby-2.3.0/gems/httparty-0.14.0/lib/httparty/response.rb:85:in `method_missing'
[112] pry(main)> zillow["searchresults"]
=> {"request"=>{"address"=>"49 Alpine Way", "citystatezip"=>"28805"},
"message"=>{"text"=>"Request successfully processed", "code"=>"0"},
私は何が欠けていますか?
を使用することができます
zpid
を取得するには、キーの連鎖を逃した!!!!私はまだRubyの新人ですし、それを理解しようと約2時間を費やしました....私はそれが何か簡単だと思った.... :-)もう一度おねがいします。 – pjw23