J'ai une application iPhone qui obtient une chaîne json d'un serveur et l'analyse. Il contient des données et, par exemple. un tableau de commentaires. Mais je l'ai remarqué que l'ordre du tableau JSON est pas conservée quand je parse comme ceci:Objective-C SBJSON: ordre de json array
// 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]);
}
Structure 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
}
}
Est-ce que quelqu'un sait comment faire face à ce problème ? Merci beaucoup!
Merci, donc les identifiants dans ce json doivent être commandés pour résoudre ce problème? Est-il possible de l'analyser pour que [arrayAfterSomeGreatFunction objectAtIndex: 0] renvoie la chaîne "comment 1"? – Cocoprogrmr
J'ai édité ma réponse pour vous montrer une façon possible de créer un nouveau tableau avec les objets triés. – Sven