How's it going folks---I'm having trouble iterating through an array in xcode--hoping someone can point me in the right direction..here's my response json response
NSString *str=@"jsonUrlremoved";
NSURL *url=[NSURL URLWithString:str];
NSData *data=[NSData dataWithContentsOfURL:url];
NSError *error=nil;
id response=[NSJSONSerialization JSONObjectWithData:data options:
NSJSONReadingMutableContainers error:&error];
{
"item":{
"1":{
"title":"Item Title",
"description":"long description",
"date":" March 01, 2014"
},
"2":{
"title":"Item Title",
"description":"long description",
"date":" March 01, 2014"
},
"3":{
"title":"Item Title",
"description":"long description",
"date":" March 01, 2014"
}
}
}
I've tried converting to nsdictionary as well as nsobject and nsarray with no luck (cause I'm a noob)
NSDictionary *results = [response objectForKey:@"item"];
for (NSDictionary *result in results) {
NSString *image = [result objectForKey:@"image"];
NSString *desc = [result objectForKey:@"description"];
NSString *title = [result objectForKey:@"title"];
}
The app either crashes or returns null---any guidance is appreciated
[response objectForKey:@"item"];returns something other thanNSDictionary, orNSArray, you need to double-check theresponseobject you're getting from the call toJSONObjectWithData: