I have a file:
{
"MapName" : "This is map1";
}
Which I try to read in with:
- (id)initFromFile:(NSString *)mapName
{
self = [super init];
if (self) {
NSString* path = [[NSBundle mainBundle] pathForResource:mapName ofType:@"json"];
NSData* jsonData = [NSData dataWithContentsOfFile:path];
assert(jsonData);
JSONDecoder* decoder = [[JSONDecoder alloc]
initWithParseOptions:JKParseOptionNone];
assert(decoder);
NSDictionary* json = (NSDictionary*)[decoder objectWithData:jsonData];
assert(json);
NSString* mapName = (NSString*)[json objectForKey:@"MapName"];
assert(mapName);
printf("MapName: %s\n", [mapName UTF8String]);
}
return self;
}
Which fails at assert(json); Is there anything obvious i'm doing wrong?
I know the file is being read ok but the decode is passing back NULL.
Thanks
use comma instead of semicolon
Validate here jsonlint.com