以下是我如何迭代我的Json"数据":
[myObject removeAllObjects];
NSDictionary *dic = jsonData[@"data"];
for (NSArray *ar in dic) {
[myObject addObject:ar];
}
这是NSLog for myObject:
myObject: (
23,
22,
21
)
如何迭代所有"数据" (在21,22,23等中)将有关公司的信息添加到myObject数组中?
我的Json结构:
{
"data": {
"21": {
"id": "21",
"company_id": "17",
"company_name": "Company 1",
"logo_url": "http://www.company.com/1.png",
"status": "2",
"allow_name": "N",
"allow_address": "N",
"allow_email": "N",
"allow_phone": "N",
"allow_birthday": "N",
"allow_gender": "N",
"created": false
},
"22": {
"id": "22",
"company_id": "5",
"company_name": "Company 2",
"logo_url": "http://www.company.com/2.png",
"status": "2",
"allow_name": "N",
"allow_address": "N",
"allow_email": "N",
"allow_phone": "N",
"allow_birthday": "N",
"allow_gender": "N",
"created": false
}
},
"success": 1
}
答案 0 :(得分:0)
您应该在您的字典中附加以下语法。
[valueForKey:@"company_name"]
查看以下教程:http://iosdevtips.co/post/80598241763/valueforkey-nsarray
答案 1 :(得分:0)
NSMutableArray *aryData = [NSMutableArray new];
for (int i=0; i<myObject.count; i++) {
[aryData addObject:myObject[i]];
}