When outputting the entire parsed JSON object it works fine, however when trying to output the value of a key it comes up with (null)
The parsing code:
-(NSString *)getNews{
__block NSString *strReturn;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://URL/URL.json"]];
__block NSDictionary *json;
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
json = [NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];
NSLog(@"Async JSON news: %@", json[@"ID"]);
//strReturn = json[@"ID"];
}];
return strReturn = @"Hello";
}
This here is from the JSON output file on the server;
[{"ID":"1","Item Description":"Test News Item Active","News Text":"This is a test news story.\r\n\r\nit should have a few line breaks.\r\n\r\nbut that's about it.","Valid From":"2014-05-23 00:00:00","Valid To":"2014-09-30 23:59:59"}]
Can anybody tell me why it is not finding the value of key ID
?