我想弄清楚如何从应用程序本地访问json文件。目前我一直在远程使用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];
感谢
是我保存到应用程序。 – hanumanDev 2013-02-15 23:27:33
你是怎么保存它的?哪条路?你应该能够很容易地做到“反向”:-) – Vinzius 2013-02-15 23:28:54
我将它复制到项目中,就像将图像拖放到ios应用程序中一样 – hanumanDev 2013-02-15 23:32:51