私はファイルを持っています:
{
"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が返されます。
ありがとう