gpt4 book ai didi

ios - 我想念在 firebase 中解析 JSON 的任何内容吗

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

我花了很多时间想不通。为什么为什么不解析。 enter image description here

func fetchUser(_ uid: String) {
FIRDatabase.database().reference().child("users").child("g373gSvDcFhXNAGh5V6vg7sU5C02").observe(.childAdded, with: {
(snapshot) in
//TODO...

print(snapshot) //Snap (email) test1@gmail.com
let user = snapshot.value as ? [String: Any]

print(user) //nil

if let _nameLabel = self.nameLabel,
let name = user ? ["name"] as ? String {
_nameLabel.text = "{-} \(name)"
}

}, withCancel: nil)

}

最佳答案

问题:

您使用事件类型 .childAdded 进行观察

case childAdded is fired when a new child node is added to a location

解决方案:

您应该将事件类型从 .childAdded 更改为 .value,如下所示:

FIRDatabase.database().reference().child("users").child("g373gSvDcFhXNAGh5V6vg7sU5C02").observe(.value, with: { (snapshot) in

// other code

})

关于ios - 我想念在 firebase 中解析 JSON 的任何内容吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41784134/

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