I receive the snapshot from Firebase server like the log below. Now I want to loop all key in snapshot but I got messy position.
I don\'t know why this happened. Any h
When you print a FDataSnapshot, it prints the JSON structure. Since JSON has no defined order for child nodes, the order in which they are shown is undetermined (although frequently it will print the children in lexicographical order of they key as you get here).
Firebase's queries can be used to get the data in a specific order. For example from this question:
[[languagesRef queryOrderedByChild:@"distance"] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
for ( FDataSnapshot *child in snapshot.children) {
NSLog(@"child.key = %@",child.key);
}
The Firebase snapshot contains additional information about the ordering of the child data, that it doesn't show when you print that snapshot. When you loop over the children of the snapshot, this ordering information is used to ensure the correct order in the loop above.