0

私はファイルを持っています:

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

私が読み込もうとしているもの:

- (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;
}

これはassert(json);で失敗します。私が間違っていることは明らかですか?

ファイルが正常に読み取られていることはわかっていますが、デコードによってNULLが返されます。

ありがとう

4

1 に答える 1

0

セミコロンの代わりにコンマを使用する

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

ここで検証jsonlint.com

于 2011-11-05T20:59:10.373 に答える