IOS5でJSONをIN ORDERで解析しようとして、私は非常に苦労しました。サーバーから順番に来ているので、そうではないことはわかっています。これが私のコードです:
NSArray *userData = [update JSONValue];
NSLog(@"USERDATA%@", userData);
NSEnumerator *enumerator = [userData objectEnumerator];
id key;
while (key = [enumerator nextObject]) {
NSDictionary *value = key;
NSString *comment = [value objectForKey:@"comment"];
NSLog(@"USERCOMMENT %@", comment);
}
最初の NSLog、すべてが美しく見えます。2 番目の NSLog は、すべてを順不同にしています。私はほとんど頭がおかしくなっています。
最初の NSLOG:
USERDATA{
1 = {
comment = "Test 6";
photoID = 1;
postedDate = "2 days ago";
userID = 17;
userPic = "members/0/image01.png";
username = kismet;
};
2 = {
comment = "Test 5";
photoID = 1;
postedDate = "2 days ago";
userID = 17;
userPic = "members/0/image01.png";
username = kismet;
};
3 = {
comment = "Test 4";
photoID = 1;
postedDate = "2 days ago";
userID = 17;
userPic = "members/0/image01.png";
username = kismet;
};
4 = {
comment = "Test 3";
photoID = 1;
postedDate = "2 days ago";
userID = 17;
userPic = "members/0/image01.png";
username = kismet;
};
5 = {
comment = "Test 2";
photoID = 1;
postedDate = "2 days ago";
userID = 17;
userPic = "members/0/image01.png";
username = kismet;
};
6 = {
comment = "Test 1";
photoID = 1;
postedDate = "2 days ago";
userID = 17;
userPic = "members/0/image01.png";
username = kismet;
};
}
2 番目の NSLog:
USERCOMMENT Test 4
USERCOMMENT Test 6
USERCOMMENT Test 1
USERCOMMENT Test 3
USERCOMMENT Test 5
USERCOMMENT Test 2