1

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 ?

1
  • 1
    Well, this isn't a valid JSON and if parser doesn't want to parse it, it's absolutely right. Commented Jun 11, 2012 at 22:30

1 Answer 1

1

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(",")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.