Follow LostMuser on Twitter

Saturday, December 11, 2010

Parsing Flickr's Invalid Json

Flickr's api returns invalid Json. The two main iOS Json parsers barf on any json from Flickr.


Turns out Flickr escapes single quotes (') and apparently this isn't allowed. The Json parser error message is not helpful for figuring this out.


By train and error I figured out doing a simple search to remove the backslashes before single quotes gets around the issue.


Here is the code I used to do so.


str = [str stringByReplacingOccurrencesOfString:@"\\'" withString:@"'"];


Oh yeah one more thing, here's the easy flickr url for getting images:

http://api.flickr.com/services/feeds/photos_public.gne?tags=san+francisco,bicycle,biking,golden+gate+bridge&tagmode=all&format=json

2 comments:

  1. Interesting. Currently having similar Json parser struggle with Foresquare's new v2 API (12/10/10) at Startup Weekend Redmond.

    When the dot method parsing Json does not work, how do you print out the Json request to see what is really happening?

    -cliveb

    ReplyDelete
  2. Are you building this for the iPhone or in Javascript? I'm not aware of a dot method on the iPhone.

    ReplyDelete

Musing's Blog Viewer Webcam



(People reading the blog right now!)