Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 905
Chris Avatar asked Feb 19 '12 21:02

Chris


1 Answers

You want

result = JSON.parse(response.body)

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

like image 90
Marc Talbot Avatar answered Sep 28 '22 07:09

Marc Talbot