我试图从firebase数据库中检索receiverId
(下面的JSON)。我知道如何使用.Value
来完成此操作,但我在使用.ChildAdded
时遇到了麻烦。
let postKey = "-KSJiJjUeuDQLZ7TsWAZ"
FIRDatabase.database().reference().child("version_one/frontEnd/post/\(postKey)").observeEventType(.ChildAdded, withBlock: {snapshot in
print(snapshot)
})
当我使用.ChildAdded
检索时,我得到了
Snap (postDescription) My car broke down
Snap (postTitle) I need a ride tot the store
Snap (receiverId) 70SOFFoklaS6xiZI9i9S3UswXuf2
Snap (senderId) HKLJ72JgNOZRP6fnOvmyow5jwbA2
Snap (status) 0
我不知道如何进入Snap
使用receiverId
获取70SOFFoklaS6xiZI9i9S3UswXuf2
{
"version_one" : {
"frontEnd" : {
"post" : {
"-KSJiJjUeuDQLZ7TsWAZ" : {
"postDescription" : "My car broke down ",
"postTitle" : "I need a ride tot the store",
"receiverId" : "70SOFFoklaS6xiZI9i9S3UswXuf2",
"senderId" : "HKLJ72JgNOZRP6fnOvmyow5jwbA2",
"status" : 0
}
},
答案 0 :(得分:0)
我认为您正在寻找:
snapshot.child("receiverId").value as! String
这将获取快照的receiverId
子项,然后从中获取字符串值。