如何获得编号JSON 数据中的对象数?
How to get the no. of objects in JSON Data?
如果我在 NSDictionary 中保存我的数据 "dict"
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableLeaves error:nil];
我怎么知道我在季节中有多少对象,我知道如何保存 NSArray 并且它是计数的,但它实际上不是一个数组。我在 Whosebug 上看到的所有问题都使用数组对象。
{ "seasons":{
"Season 0":{ },
"Season 1":{ }
}
试试这个它会给出值/键的数组
[dict allValues]; or [dict allKeys]
NSDictionary 有一个 count
方法:
NSInteger count = [dict[@"seasons"] count]; // Returns 2
如果我在 NSDictionary 中保存我的数据 "dict"
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableLeaves error:nil];
我怎么知道我在季节中有多少对象,我知道如何保存 NSArray 并且它是计数的,但它实际上不是一个数组。我在 Whosebug 上看到的所有问题都使用数组对象。
{ "seasons":{
"Season 0":{ },
"Season 1":{ }
}
试试这个它会给出值/键的数组
[dict allValues]; or [dict allKeys]
NSDictionary 有一个 count
方法:
NSInteger count = [dict[@"seasons"] count]; // Returns 2