Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSJSONSerialization

I have problems with some public json services with serveices formatted this way

jsonFlickrFeed({
        "title": "Uploads from everyone",
        "link": "http://www.flickr.com/photos/",
        "description": "",
        "modifi ... })

NSJSONSerialization seems to be unable to make its work

NSURL *jsonUrl = [NSURL URLWithString:@"http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback"];
NSError *error = nil;
NSData *jsonData = [NSData dataWithContentsOfURL:jsonUrl options:kNilOptions error:&error];
NSMutableDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error];
NSLog(@"%@", jsonResponse);
like image 790
GAVELLO Avatar asked Dec 30 '11 22:12

GAVELLO


2 Answers

Using the latest web API I have solved my problem.

For reference, the old web API is: http://api.flickr.com/services/feeds/photos_public.gne?id=xxxxxxxx&lang=en-us&format=json

The current web API is: http://api.flickr.com/services/feeds/photos_public.gne?id=xxxxxxxx&lang=en-us&format=json&nojsoncallback=1

It's done.

like image 186
Hiren Patel Avatar answered Nov 15 '22 19:11

Hiren Patel


I think that NSJSONSerialization can't deal with the jsonFlickrFeed ( ... ) in your JSON code. The problem is that the pure response is invalid JSON (test it here).

So you will have to build a way around this issue. You could for example search for the string jsonFlickrFeed( in the response and delete it or - the easier way - just cut off the beginning until the valid JSON starts and cut off the last character (which should be the bracket).

like image 40
Paul Avatar answered Nov 15 '22 21:11

Paul