【发布时间】:2017-01-17 18:47:43
【问题描述】:
我有这个 JSON 结构:
{
"Devices" : {
"1EJ8QmEQBJfBez7PMADbftCjVff1" : {
"Device1" : {
"Category" : "Others",
"Description" : "",
"DeviceName" : "",
"ImageUrl" : ""
},
"Device2" : {
"Category" : "Chairs",
"Description" : "",
"DeviceName" : "",
"ImageUrl" : ""
},
"Device3" : {
"Category" : "Others",
"Description" : "",
"DeviceName" : "",
"ImageUrl" : ""
}
},
"97PUAcUC5UYxLpBOLnC4yQjxiEf2" : {
"Device1" : {
"Category" : "Others",
"Description" : "",
"DeviceName" : "",
"ImageUrl" : ""
},
"Device2" : {
"Category" : "Books",
"Description" : "",
"DeviceName" : "",
"ImageUrl" : ""
},
"Device3" : {
"Category" : "Chairs",
"Description" : "",
"DeviceName" : "",
"ImageUrl" : ""
}
}
},
"UserProfile" : {
"1EJ8QmEQBJfBez7PMADbftCjVff1" : {
"city" : "",
"email" : "",
"name" : "",
"phone" : ""
},
"97PUAcUC5UYxLpBOLnC4yQjxiEf2" : {
"city" : "",
"email" : "",
"name" : "",
"phone" : ""
},
}
}
我想访问每个设备中的类别节点? 那可能吗? 因为我想检索所有具有相同类别的节点的数据!
let ref = FIRDatabase.database().reference().child("Devices")
ref.queryOrderedByChild("Category")
我已尝试访问设备!然后直接进入类别! 看来这不是正确的方法!
别告诉我我需要改变 JSON 的结构!
有什么方法可以访问用户ID吗?
【问题讨论】:
-
没有通配符机制,所以我认为你必须重组。
-
建议是扁平化数据结构并合并冗余 - firebase.google.com/docs/database/web/structure-data
-
有,但你需要在拥有所有设备后在代码中完成。
标签: json swift firebase firebase-realtime-database nosql