I am trying to iterate trough a JSON array to get both the item key and value.
This is my JSON array:
{
"ClientData": [{
"Name": "Michael"
}, {
"Last": "Ortiz"
}, {
"Phone": "5555555555"
}, {
"email": "[email protected]"
}],
"ClientAccess": [{
"T-Shirt": "YES"
}, {
"Meals": "NO"
}, {
"VIP": "YES"
}, {
"Registration Completed": "Pending"
}]
}
Now, I am trying to iterate through the "ClientData" array, but for some reason the app is crashing with this exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance
This is the code I am using to iterate through the JSON array:
NSDictionary* object = [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:nil];
// Client Profile Data
NSDictionary *clientDataDict = [object objectForKey:@"ClientData"];
for (id item in clientDataDict)
{
[JSONUserData addObject:[clientDataDict objectForKey:item]];
}
This code was working fine when I didn't have each item on the JSON array placed inside an array. I did this to keep a consecutive order on the array.
Can someone give me any pointers on what the problem is?
Thank you!