本文介绍了在Firebase中循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找到一种方法来打印/隔离Firebase中JSON数据结构的一部分中的每个子级.我正在使用swift,并提到了另一篇文章,并对此进行了验证.

I have been trying to find a way to print/isolate each of the children in a part of the JSON data structure in Firebase. I am using swift and another post mentioned and verified this as the solution.

for child in snapshot.childSnapshotForPath("vets").children {
    print(child.key)
}

但这是无效的,因为它带有此警告.

but this is not valid because it comes with this warning.

Ambiguous use of 'key'

您如何建议我遍历数据?感谢所有帮助.

how do you recommend I loop through the data? All help is greatly appreciated.

推荐答案

尝试一下:

FIRDatabase.database().reference().child("vets").observeEventType(.Value, withBlock: { snapshot in
        if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
            for child in snapshots {
                print("Child: ", child)
            }
        }

    })

这篇关于在Firebase中循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 20:15