I'm trying to access JSON data that I have taken from a website and stored in an array. First, however, I want to filter out everything but the "title" information, which I am doing using the valueForKey: method. In order to test this I am writing them to the log using the NSLog method, however when I run this I get "null".
Can anyone advise me, as to why I'm getting what I'm getting?
Thanks for your help, much appreciated.
{
NSURL *redditURL = [NSURL URLWithString:@"http://pastebin.com/raw.php?i=FHJVZ4b7"];
NSError *error = nil;
NSString *jsonString = [NSString stringWithContentsOfURL:redditURL encoding:NSASCIIStringEncoding error:&error];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
NSMutableArray *titles = [json valueForKey:@"title"];
NSLog(@"%@", json);
}
jsonStringand thejsonarray to the console (via NSLog). This should give you the idea what is going wrong. Presumably it the response from the URL not an array but a dictionary.arrayit should go into adictionary?