bishop3000
asked on
How to extract values from string in Ruby on Rails
I'm a novice trying to extract the latitude and longitude values (under geometry > location) from the attached JSON.
I tried to use this legacy code without success:
I figured out how to convert to key-value pairs with:
I thought this would be obvious, but didn't find the solution through googling. Thanks a lot for your help.
JSON-text.txt
JSON-text-as-key-value-pairs.txt
I tried to use this legacy code without success:
results_array = ActiveSupport::JSON.decode response.body
if results_array && "OK" == results_array["status"]
results_array["results"].each do |result|
puts logger.info lat = result["geometry"]["location"]["lat"]
end
I figured out how to convert to key-value pairs with:
response_2 = JSON.parse(response.body)
...But still couldn't figure out how to extract the latitude and longitude. I thought this would be obvious, but didn't find the solution through googling. Thanks a lot for your help.
JSON-text.txt
JSON-text-as-key-value-pairs.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome, glad it helped you out :)
ASKER
Here's what I ended up with, which works.
Open in new window