我需要使用NS
JSONSerialization类参考读取JSON文件,我发现的有关此类使用的所有示例都从网页本身读取内容,而不是从之前创建的JSON文件中读取.任何人都知道如何使用该类从JSON文件解析?谢谢.
@H_502_4@
简单,快速的例子:
- NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"foobar"
- ofType:@"json"];
- NSData *data = [NSData dataWithContentsOfFile:jsonPath];
- NSError *error = nil;
- id json = [NSJSONSerialization JSONObjectWithData:data
- options:kNilOptions
- error:&error];
- NSLog(@"JSON: %@",json);