gpt4 book ai didi

json - firebase 数组解析 json 总是失败

转载 作者:行者123 更新时间:2023-11-28 15:42:53 25 4
gpt4 key购买 nike

这是我打印的 print(childSnap) 并尝试使用 as? [String : Any] 但任何替代方案总是失败。

   Snap (-Ki9GkBvIMofJiIByVeI) {
location = Cupertino;
name = "find hotel ";
userCreatedId = "";
}

 let ref = FIRDatabase.database().reference()
let allGroup = ref.child("all-group")
allGroup.observe(.childAdded, with: { (snapshot) in
for childSnap in snapshot.children{
print(childSnap)

if let _childSnap = childSnap as? [String : Any] {
//this code not execute..
let group = Group(json: _childSnap )
groups.append(group)
}
}

}, withCancel: nil)
}

最佳答案

childSnap 类型转换为 FIRDataSnapshot,然后访问它的 value 属性。

if let _childSnap = (childSnap as! FIRDataSnapshot).value as? [String : Any] {
let group = Group(json: _childSnap )
groups.append(group)
}

关于json - firebase 数组解析 json 总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43515144/

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