我试图弄清楚如何从应用程序中本地访问 json 文件。目前我一直在从这样的服务器远程使用 json 文件:
jsonStringCategory = @"http://****categories?country=us";
}
// Download the JSON file
NSString *jsonString = [NSString
stringWithContentsOfURL:[NSURL URLWithString:jsonStringCategory]
encoding:NSStringEncodingConversionAllowLossy|NSUTF8StringEncoding
error:nil];
NSLog(@"jsonStringCategory is %@", jsonStringCategory);
NSMutableArray *itemsTMP = [[NSMutableArray alloc] init];
// Create parser
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
itemsTMP = [results objectForKey:@"results"];
self.arForTable = [itemsTMP copy];
[self.tableView reloadData];
我试过这个:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"categoriesus" ofType:@"json"];
jsonStringCategory = [[NSString alloc] initWithContentsOfFile:filePath];
谢谢