我讀過關於這個題目其他答案,如:的Rails:解析HTTParty
HTTParty parsing JSON in Rails
但是,我仍然無法弄清楚如何分析我的迴應接收。
response.parsed_response = HTTParty.get(url, query: params)
回報:
=> #<HTTParty::Response:0x89435d0 parsed_response="http://foo.com", @response=#<Net::HTTPOK 200 OK readbody=true>, @headers={"cache-control"=>["no-cache", "no-store"], "date"=>["Tue, 21 Feb 2017 23:10:47 GMT"], "expires"=>["Thu, 01 Jan 1970 00:00:00 GMT"], "p3p"=>["CP=\"ALL IND DSP COR CUR ADM TAIo PSDo OUR COM INT NAV PUR STA UNI\""], "pragma"=>["no-cache"], "server"=>["Apache-Coyote/1.1"], "set-cookie"=>["bar.Agent.p=c1921b97d1f8a0918621c48bd32ded2b; Domain=.bar.com; Expires=Fri, 19-Feb-2027 23:10:47 GMT; Path=/"], "content-length"=>["366"], "connection"=>["Close"]}>
我需要parsed_response
後出現的URL。其他答案似乎打破了parsed_response之後出現的哈希,但我只是尋找parsed_response後出現的url(並且它只出現在響應中)。
我試過了: puts response
它返回上面的整個響應。
puts response.parsed_response
返回:
http://foo.com
=> nil