gpt4 book ai didi

IOS Firebase : Loop all key in snapshot. 值位置困惑

转载 作者:行者123 更新时间:2023-11-28 19:38:12 26 4
gpt4 key购买 nike

我从 Firebase 服务器收到快照,如下面的日志所示。现在我想循环快照中的所有键,但我的位置很乱。

我不知道为什么会这样。任何帮助将不胜感激

打印日志的代码

NSLog(@"snapshot = %@",snapshot.value);
for (NSString *keyPath in snapshot.value) {
NSLog(@"keyPath = %@",keyPath);
}

这是日志

2016-04-20 11:48:04.177 EarCrush[5241:79090] snapshot = {
"-KFlrXzqsSa50GVnJkqk" = {
conversationID = "2886-2377";
text = Okteh;
time = "20-04-2016 11:12";
};
"-KFlrgrvdR_uj2o1ltaw" = {
conversationID = "2886-2377";
text = "How are you determining";
time = "20-04-2016 11:12";
};
"-KFlrhSBbVnx4XyWjQPy" = {
conversationID = "2886-2377";
text = "Message 2 ..... ";
time = "20-04-2016 11:12";
};
"-KFlrhzx0TK5CeSR3aAA" = {
conversationID = "2886-2377";
text = "Message 3: Hello world ";
time = "20-04-2016 11:12";
};
}
2016-04-20 11:48:04.177 EarCrush[5241:79090] keyPath = -KFlrhzx0TK5CeSR3aAA
2016-04-20 11:48:04.178 EarCrush[5241:79090] keyPath = -KFlrhSBbVnx4XyWjQPy
2016-04-20 11:48:04.179 EarCrush[5241:79090] keyPath = -KFlrXzqsSa50GVnJkqk
2016-04-20 11:48:04.179 EarCrush[5241:79090] keyPath = -KFlrgrvdR_uj2o1ltaw

Firebase 服务器图片 enter image description here

最佳答案

当您打印 FDataSnapshot 时,它会打印 JSON 结构。由于 JSON 没有为子节点定义顺序,因此它们的显示顺序是不确定的(尽管它经常会在您到达这里时按照它们键的字典顺序打印子节点)。

Firebase's queries可用于按特定顺序获取数据。例如来自 this question :

[[languagesRef queryOrderedByChild:@"distance"] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {

for ( FDataSnapshot *child in snapshot.children) {

NSLog(@"child.key = %@",child.key);

}

Firebase 快照包含有关子数据排序的附加信息,打印该快照时不会显示这些信息。当您遍历快照的子项时,此排序信息用于确保上面循环中的正确顺序。

关于IOS Firebase : Loop all key in snapshot. 值位置困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36734164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com