我有一个iPhone应用程序从服务器获取json字符串并对其进行解析。它包含一些数据,例如。一系列评论。但我注意到,当我分析它像这样JSON数组的顺序不会保留:Objective-C SBJSON:json数组的顺序
// parse response as json
SBJSON *jsonParser = [SBJSON new];
NSDictionary *jsonData = [jsonParser objectWithString:jsonResponse error:nil];
NSDictionary* tmpDict = [jsonData objectForKey:@"rows"];
NSLog(@"keys coming!");
NSArray* keys = [tmpDict allKeys];
for (int i = 0;i< [keys count]; i++) {
NSLog([keys objectAtIndex:i]);
}
JSON结构:
{
"pagerInfo":{
"page":"1",
"rowsPerPage":15,
"rowsCount":"100"
},
"rows":{
"18545":{
"id":"18545",
"text":"comment 1"
},
"22464":{
"id":"22464",
"text":"comment 2"
},
"21069":{
"id":"21069",
"text":"comment 3"
},
… more items
}
}
有谁知道如何解决这个问题?非常感谢!
谢谢,所以这个json中的ID必须被命令解决这个问题?有没有什么办法解析它,以便[arrayAfterSomeGreatFunction objectAtIndex:0]会返回“comment 1”字符串? – Cocoprogrmr 2010-09-21 10:02:01
我编辑了我的答案,向您展示了一种可能的方式来创建具有排序对象的新数组。 – Sven 2010-09-21 10:39:29