I have the following code that I run at viewDidLoad:
NSString *json_list = [[NSBundle mainBundle] pathForResource:@"mylist" ofType:@"json"];
NSData *theList = [NSData dataWithContentsOfFile: json_list];
NSInputStream *listStream = [[NSInputStream alloc] initWithData:theList];
[listStream open];
if (showStream) {
NSError *parseError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithStream:listStream options:NSJSONReadingAllowFragments error:&parseError];
if ([jsonObject respondsToSelector:@selector(objectForKey:)]) {
for (NSDictionary *firstItem in [jsonObject objectForKey:@"list"]) {
NSLog(@"Title: %@", [firstItem objectForKey:@"title"]);
}
}
} else {
NSLog(@"Failed to open stream.");
}
All is OK but I would like to store this information into say an array so that I can use later within this view, but I have had a go at soem various array methods mutable etc but seem to have got stuck at this part of it:
Ideally instead of the NSLog bit:
NSLog(@"Title: %@", [firstItem objectForKey:@"title"]);
this is where I would probably add it to an array, but how can I do this to use later on?
Thanks