TypeError:无法将Net :: HTTPOK转换为String [英] TypeError: can't convert Net::HTTPOK into String
本文介绍了TypeError:无法将Net :: HTTPOK转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用net/http
和json
通过Google的地理编码API对地址进行地理编码.这是引发错误的地方:
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)
响应是Net :: HTTPOK类的,但是我想访问实际的JSON响应数据(而不仅仅是状态码).
The response is of class Net::HTTPOK, but I want to access the actual JSON response data (not just the status code).
推荐答案
您想要的
result = JSON.parse(response.body)
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTPResponse.html
这篇关于TypeError:无法将Net :: HTTPOK转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文