Reputation: 721
i have a problem when try to get and parse a remote JSON.
require 'net/http'
require 'json'
url = "Www.example.com"
resp = Net::HTTP.get_response(URI.parse(url))
buffer = resp.body
result = JSON.parse(buffer)
details = result['Detail']
details.each do |detail|
puts "Latitude: #{detail['Latitude']}"
end
The JSON returned it's like this.
{Detail:{ID:578155,Latitude:69.83}}
Any suggestion please ?
Upvotes: 1
Views: 2636
Reputation: 721
It's not a valid JSON, so i use split and gsub methods to parse it.
string = string.split("}")
string = string[0].gsub("[", "")
string = string[0].gsub("]", "")
string = string.split(",")
Upvotes: 1