2016-05-11 124 views
0

我想通过使用http获得JSON响应。 这里是我的一小段代码片段如何使用ruby获得JSON响应

http = Net::HTTP.new(uri.host, uri.port) 
     http.open_timeout = 300 
     http.read_timeout = 300 
     if uri.scheme == 'https' 
     http.use_ssl = true 
     http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE 
     end 
http.request(Net::HTTP::Get.new(uri.request_uri, initheader = {'header' => 'headervalue'})).body 

,但我越来越喜欢响应

[{\"Id\":\"986\",\"DataContentType\":2,\"DataContent\":\"content type\",\"lang\":\"ENGLISH\",\"Name\":\"Name\"}] 
+0

这是json响应。 –

+1

这看起来像一个有效的JSON字符串。解析它,使用'JSON.parse(...)' – Stefan

+0

然后请“关闭”这个问题(写一个答案并接受 - 并且对@Stefan很好)。 – Felix

回答

0

这种反应看起来像JSON你只需要解析使用JSON.parse(string_here)

感谢那些JSON。