I am trying to get a value for a particular key from a dictionary but i get a \"[__NSCFArray objectForKey:]: unrecognized selector sent to instance \"
-(voi
The problem is you have a NSArray
not an NSDictionary
. The NSArray
has a count of 1 and contains an NSDictionary
.
NSArray *wrapper= [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSDictionary *avatars = [wrapper objectAtIndex:0];
To loop through all items in the array, enumerate the array.
NSArray *avatars= [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
for (NSDictionary *avatar in avatars) {
NSDictionary *avatarimage = avatar[@"image"];
NSString *name = avatar[@"name"];
// THE REST OF YOUR CODE
}
NOTE: I also switched from -objectForKey:
to [] syntax. I like that better.