Why is my JSON.parse not working? Ruby on the rails

I am trying to load images from the Flickr API into a Ruby on Rails application, but I get an "Unexpected Token" in my JSON.parse () line.

I found another answer here, where the returned JSON had double quotes, and the solution was to add .gsub to the end, but I still get the error message.

Does anyone know what the problem is?

def add @jsonresults = open("http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&api_key=bb398c11934abb6d51bdd720020f6a4a&per_page=1&page=1&format=json&nojsoncallback=1").read @images = JSON.parse(@jsonresults.to_json.gsub('\"', '"')) end 

Error:

 JSON::ParserError in ImagesController#add 757: unexpected token at '"{"photos":{"page":1, "pages":500, "perpage":1, "total":500, "photo":[{"id":"8234011021", "owner":" 24066605@N07 ", "secret":"b4c05df8c5", "server":"8341", "farm":9, "title":"Crescent Lake", "ispublic":1, "isfriend":0, "isfamily":0}]}, "stat":"ok"}"' 
+4
source share
2 answers

The disk returned by the call looks great. Change your parsing:

 @images = JSON.parse(@jsonresults) 
+5
source

This is not valid JSON. The external set of double quotes does not belong. This is a valid version:

 '{"photos":{"page":1, "pages":500, "perpage":1, "total":500, "photo":[{"id":"8234011021", "owner":" 24066605@N07 ", "secret":"b4c05df8c5", "server":"8341", "farm":9, "title":"Crescent Lake", "ispublic":1, "isfriend":0, "isfamily":0}]}, "stat":"ok"}' 
+1
source

All Articles