好的,这是我在 Objective-C 中使用 JSON 的第一种方法(我对最后一种方法也很陌生)。我要获取存储在我的 json 中的信息以在 Objective-C 中使用它们,但是当尝试加载它时,我得到 null 作为响应NSLog(@"%@",allData);
。谁能告诉我我做错了什么?提前感谢您的时间和耐心。哦,如果需要,这里是 json:
http://jsonviewer.stack.hu/#http: //conqui.it/ricette.json
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"json"];
NSError *error = nil;
NSMutableData *JSONData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
NSLog(@"%@",JSONData);
NSArray *allData = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:nil];
NSLog(@"%@",allData);
for (NSDictionary *diction in allData) {
NSString *recipe = [diction objectForKey:@"recipe"];
[array addObject:recipe];
}
NSLog(@"%@",array);