I use touchjson library. I receive json structure.
{"My dishes": ""}if i have not my dishes or{"My dishes": [{"dish": "rice with fish""restaurant_id": "35", "latitude": "39.783871","longitude": "-96.314759"}]}if i have a dish.
–
NSDictionary *all_dish = [dictionary objectForKey:@"My dishes"];
for (NSDictionary *my_dish in all_dish) {
//some code
}
in the first case , i get
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x2900688'
How to solve the problem?
In the first case the object for key
My dishesis not a dictionary, but aNSString, which does not support fast enumeration.In the second case,
all_dishesisn’t aNSDictionarybut aNSArray. I am surprised it works.The way no dishes is handled is broken from where I stand: if you have no dishes
My dishesshould have a value ofnullor an empty list, not “”.If you can’t control this, check whether the value of
My dishesis anNSArraybefore attempting to enumerate over it.