本文介绍了快速访问嵌套的Firebase数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用数据结构,并且正在遍历几个节点,这是我得到的json数据.
I am working wth a data structure, and I am looping through a couple nodes and here is the json data I get.
Snap (20171012) { "-KwM45HyW4UduQgKTGn6" = { ImageName = "Screen Shot 2017-10-13 at 11.24.51 AM.png"; fileURL = ""; thumbFileUrl = ""; user = "User not defined"; }; "-KwM4limD2aRyHgeKE5P" = { ImageName = "test.png"; fileURL = ""; thumbFileUrl = ""; user = "User not defined"; };}
之后,我可以使用data.key访问"snap"值以获取"20171012"
After this, I can access the "snap" value using my data.key to get the "20171012"
ref.child(myselected_spot!).observe(DataEventType.value, with: { (snapshot) in if snapshot.childrenCount > 0 { for mydata in snapshot.children.allObjects as! [DataSnapshot] { if mydata.key.characters.count == 8 { self.formattedDates.append(convertDate(stringDate: mydata.key)) self.selected_dates.append(mydata.key)如何获取"ImageName"的值
How would I get the value for "ImageName"
推荐答案您的 mydata 是另一个 DataSnapshot ,因此您可以访问该类的所有方法和属性.在这种情况下,您要查找 DataSnapshot.childSnapshotForPath::
Your mydata is another DataSnapshot, so you can access all methods and properties of that class. In this case you're looking for DataSnapshot.childSnapshotForPath::
ref.child(myselected_spot!).observe(DataEventType.value, with: { (snapshot) in if snapshot.childrenCount > 0 { for mydata in snapshot.children.allObjects as! [DataSnapshot] { if mydata.key.characters.count == 8 { self.formattedDates.append(convertDate(stringDate: mydata.key)) self.selected_dates.append(mydata.key) print(mydata.childSnapshot(forPath: "ImageName").value)更多推荐
快速访问嵌套的Firebase数据
发布评论