0

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

BrendanS
  • 191
  • 13
  • Eugene was very close: { "MapName" : "This is map1" } No delimiter on last item. Comma should be used on all previous. – BrendanS Nov 05 '11 at 21:04

1 Answers1

0

use comma instead of semicolon

{
    "MapName" : "This is map1",
}

Validate here jsonlint.com

Eugene
  • 10,006
  • 4
  • 37
  • 55
  • 4
    Close. Thanks for giving me the idea to check the json. I should have have no mark as it's the last one in the collection. So no comma or semi-column. – BrendanS Nov 05 '11 at 21:02