I have a dictionary of arrays that is causing __NSCFDictionary objectAtIndex:
errors.
Can someone tell me why? The dictionary clearly has at least 1 array at the time of the error.
NSError *error;
responseString = [[NSString alloc] initWithData:self.responseData2 encoding:NSUTF8StringEncoding];
/* response string contains this:
{"words":
{
"word": {"rowsreturned":0,"id":"-1","date":"","word":"","term":"","definition":"","updated_on":""}
},
"status":"",
"rowsreturned":""
}
*/
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.responseData2 options:kNilOptions error:&error];
NSArray *todaysWord = [[json objectForKey:@"words"] objectForKey:@"word"];
//error here -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance
NSDictionary *word = [todaysWord objectAtIndex:0];
In your case
[[json objectForKey:@"words"] objectForKey:@"word"];
is returning a dictionary and not an array. Try doing the following,Your response string also shows that value for
word
is,which is a dictionary with key value pairs as
rowsreturned:0
,id:-1
etc..