TypeError: can't convert Net::HTTPOK into String
Asked Answered
F

1

7

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

Fr answered 19/2, 2012 at 21:5 Comment(0)
C
32

You want

result = JSON.parse(response.body)

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

Curl answered 19/2, 2012 at 23:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.