I'm trying to figure out how to access a json file locally, from within the app. Currently I've been using the json file remotely from a server like this:
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];
I tried this:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"categoriesus" ofType:@"json"];
jsonStringCategory = [[NSString alloc] initWithContentsOfFile:filePath];
thanks