How can I parse a longer JSON file than a NSString?
I'm a bit stuck in a project. I was writing some code to get a JSON file and store it in开发者_StackOverflow中文版 an NSString before parsing it into a NSArray.
But I get an error:
2010-10-27 20:59:44.813 GeraldKervyn[21752:207] -JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x7637890 {NSLocalizedDescription=Unrecognised leading character}"
I think the problem is related to the limited value that an NSString can take.
BTW this is the feed I'm using : http://www.geraldkervyn.com/api/get_recent_posts/
What would be the most convenient way to parse this into an NSArray ?
Thanks !
First, Add the SBJson code to your project, courtesy of Stig Brautaset. Then do this...
NSString *subject = @"http://www.geraldkervyn.com/api/get_recent_posts/";
NSString *encodedSubject =
[subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *test = [NSString stringWithContentsOfURL:[NSURL URLWithString:encodedSubject]];
SBJsonParser *parser = [[SBJsonParser new] autorelease];
NSDictionary *json = [parser objectWithString:test];
NSArray *values = [json objectForKey:@"posts"];
精彩评论