TypeError: can't convert Net::HTTPOK into String

瘦欲@ 提交于 2019-12-21 11:54:49

问题


I'm using net/http and json to geocode an address using google's Geocoding API. Here is where the error is being thrown:

response = Net::HTTP.get_response(URI.parse(url))
result = JSON.parse(response)

The response is of class Net::HTTPOK, but I want to access the actual JSON response data (not just the status code).


回答1:


You want

result = JSON.parse(response.body)

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTPResponse.html



来源:https://stackoverflow.com/questions/9353227/typeerror-cant-convert-nethttpok-into-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!