I have created an NSDictionary from a JSON file, but when I try to do
NSString *key = [NSString stringWithFormat:@"%i",indexPath.row];
NSDictionary *currentObject = [JSONdata objectForKey:key];
I error receive and error of -[__NSCFArray objectForKey:]: unrecognized selector sent to instance
When I do an NSLog of JSONdata this is my output:
(
{
1 = {
description = "";
facets = (
{
name = Red;
},
{
name = Blue;
},
{
name = Skinny;
},
{
name = Standard;
},
{
name = "Navy Blue";
}
);
id = 1073;
owner = 1001;
"post_date" = 1341980987;
transaction = 24;
username = TonyB;
};
},
{
2 = {
description = "";
facets = (
{
name = "Bow Tie";
},
{
name = Blue;
},
{
name = Orange;
},
{
name = Yellow;
}
);
id = 1001;
owner = 1001;
"post_date" = 1340640012;
transaction = 6;
username = TonyB;
};
}
)
Am I correcting in thinking that the first set of keys that I should be able to get should be 1 and 2 using [JSONdata objectForKey:@"0"] or [JSONdata objectForKey:@"1"]? Or am I missing something?
The structure of your JSON is as Follow
NSArray containing NSDictionary
So you need to do this :
[[JSONdata objectAtIndex:0] objectForKey:@"1"]Also when in doubt you can always do this :
NSLog(@"JSONdata class == %@", [JSONdata class]);And when you hit a NSDictionary you always have this method :
- (NSArray *)allKeysthat will return you an array of all the key of that dictionary.