Reputation: 43
NSString *responseString = [request responseString];
NSDictionary *dictionary=[responseString JSONValue];
NSArray *dic=[dictionary valueForKey:@"data"];
for (int a=0; a<dic.count; a++) {
NSInteger z=(NSInteger)a;
NSLog(@"%@",[[dic objectAtIndex:a] objectForKey:@"nom"]);
}
this is the file
{"data":[ "",{"id":"1","nom":"hello","message":["",{"id":1,"nom":"dad"}]}, {"id":"2","nom":"hi","message":["",{"id":"1","nom":"marie"},{"id":"2","nom":"bob"}]} ] }
When I want to parcour my json file, I saw the problem whith variable "a" in objectAtIndex
because it's an integer, but if I try value 5 for exemple it's work's perfect.
Can you help me please.
Upvotes: 0
Views: 93
Reputation: 35616
Take a look at your data
array... The very first object is an empty string. So, you're trying to send an objectForKey:
message to it (believing that is a dictionary) and you get a crash. You should either remove your object or implement a logic that would try to inspect each object before trying to pull a value.
Upvotes: 1