我一直在尝试在 IOS5 中按顺序解析我的 JSON。它是从服务器按顺序来的,所以我知道不是那样的。这是我的代码:
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,一切看起来都很漂亮。第二个 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;
};
}
第二个NSLog:
USERCOMMENT Test 4
USERCOMMENT Test 6
USERCOMMENT Test 1
USERCOMMENT Test 3
USERCOMMENT Test 5
USERCOMMENT Test 2