我已经阅读了关于这个主题的其他答案,例如:
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之后的网址。其他答案似乎分解了出现在parsed_response之后的散列,但我只是在寻找出现在parsed_response之后的url (它只出现在响应中)。
我尝试过:puts response,它返回上面的整个响应。
返回以下内容的puts response.parsed_response:
http://foo.com
=> nil发布于 2017-02-22 09:10:31
这对我来说通常很有效
response = HTTParty.get(url, options)
puts response.bodyhttps://stackoverflow.com/questions/42380135
复制相似问题