As pst pointed out, the problem turned out to be the BOM. In Xcode, if you right-click on the filename, choose "Open As" and choose "Hex", you'll see:
Those first three characters are obviously not standard text characters. Fortunately, you can highlight these three characters in the hex editor in Xcode, delete them, save the file, and it will now that should fix it.
Original answer:
Also, are you sure the JSON was included in your bundle (check "Copy Bundle Resources" in the "Build Phases" of your "Target Settings). I just parsed your JSON with Cocoa standard JSON parsing class, NSJSONSerialization
, without incident. Perhaps you should try examining the data
and make sure everything is ok:
NSLog(@"data=%@", [[[NSString alloc] initWithData:data] autorelease]);
But I parsed your JSON with both JSONKit
and NSJSONSerialization
without incident.
NSString *filename = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:filename];
if (!data)
{
NSLog(@"%s: data was nil", __FUNCTION__);
return;
}
JSONDecoder *decoder = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone];
NSError *error = nil;
id results = [decoder objectWithData:data error:&error];
// Also tested with NSJSONSerialization
//
// id results = [NSJSONSerialization JSONObjectWithData:data
// options:0
// error:&error];
if (!error)
NSLog(@"%s: results = %@", __FUNCTION__, results);
else
NSLog(@"%s: error = %@", __FUNCTION__, error);