【发布时间】:2017-07-08 19:05:34
【问题描述】:
我附上了我的 JSON 树的图片
{
"-Ko4cg3ik5OFsnLTI4q4" : {
"FacebookPage" : {
"id" : "187736205061418",
"page" : "partyunlimitedtoronto"
},
"MapView" : {
"Edate" : 523940400,
"Sdate" : 523929600,
"intersted" : 3843,
"lat" : 45.510772273476,
"lng" : -73.563586483671,
"type" : "MUSIC",
"userID" : 1373802105986614,
"visibility" : "Public"
},
"address" : "Théâtre Corona",
"bio" : "evenko & Greenland Productions présentent\t\nMogwai\navec/with Xander Harris \nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 24 mars à 10h\n\n37$ à 42$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: March 24 at 10am\n\n$37 to $42\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Mogwai // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17361785_10155183713782422_6829705267219994059_n.jpg?oh=150f6f53c74233b70b7f1b372c1db1e4&oe=59CF07EE",
"site" : "http://www.evenko.ca/fr/evenements/12392/mogwai/theatre-corona/12-06-2017",
"status" : "normal"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"FacebookPage" : {
"id" : "620998508097068",
"page" : "partyunlimitedtoronto"
},
"MapView" : {
"Edate" : 43223454,
"Sdate" : 65837495,
"interested" : 2355,
"lat" : 45.3846583,
"lng" : -74.4736583,
"type" : "Party",
"userID" : 1373802105986614,
"visibility " : "Public"
},
"address" : "Théâtre Corona",
"bio" : "Greenland Productions & evenko présentent\t\t\t\t\t\t\nNazareth\t\t\t\navec/with Les Deuxluxes\t\n\nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 14 avril à midi \n\n44,50$ à 48$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: April 14 at noon\n\n$44,50 to $48\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Nazareth // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17759677_10155255160737422_1735715699829358715_n.jpg?oh=1d6d1c250c2c6b38c6ef0de4483bd0a9&oe=5A0C4879",
"site" : "http://www.evenko.ca/fr/evenements/12489/nazareth/theatre-corona/08-03-2017",
"status" : "normal"
}
}
所以当我运行我的程序时,我试图只在每个子节点中下载“MapView”节点,但在这种情况下,我不知道“MapView”父节点的名称。在这种情况下,有没有办法只下载特定的孩子。否则,我在考虑是否应该使用这种结构风格。
{
"EventView" : {
"-Ko4cg3ik5OFsnLTI4q4" : {
"FacebookPage" : {
"id" : "187736205061418",
"page" : "partyunlimitedtoronto"
},
"address" : "Théâtre Corona",
"bio" : "evenko & Greenland Productions présentent\t\nMogwai\navec/with Xander Harris \nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 24 mars à 10h\n\n37$ à 42$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: March 24 at 10am\n\n$37 to $42\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Mogwai // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17361785_10155183713782422_6829705267219994059_n.jpg?oh=150f6f53c74233b70b7f1b372c1db1e4&oe=59CF07EE",
"site" : "http://www.evenko.ca/fr/evenements/12392/mogwai/theatre-corona/12-06-2017",
"status" : "normal"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"FacebookPage" : {
"id" : "620998508097068",
"page" : "partyunlimitedtoronto"
},
"address" : "Théâtre Corona",
"bio" : "Greenland Productions & evenko présentent\t\t\t\t\t\t\nNazareth\t\t\t\navec/with Les Deuxluxes\t\n\nPortes: 19h00 - Spectacle: 20h00\n\nMise en vente: 14 avril à midi \n\n44,50$ à 48$\n\nPrix lors de l’achat à la billetterie / Des frais de manutention peuvent s’appliquer lors de l’achat en ligne.\n\n.....................................................\n\nDoors: 7:00 pm - Show: 8:00 pm\n\nOn Sale: April 14 at noon\n\n$44,50 to $48\n\nPrices for box office purchase / Handling fees may apply for online purchase.",
"name" : "Nazareth // Montréal",
"pic" : "https://scontent.xx.fbcdn.net/v/t1.0-9/17759677_10155255160737422_1735715699829358715_n.jpg?oh=1d6d1c250c2c6b38c6ef0de4483bd0a9&oe=5A0C4879",
"site" : "http://www.evenko.ca/fr/evenements/12489/nazareth/theatre-corona/08-03-2017",
"status" : "normal"
}
},
"MapView" : {
"-Ko4cg3ik5OFsnLTI4q4" : {
"Edate" : 534312000,
"Sdate" : 534301200,
"intersted" : 652,
"lat" : 45.4827983,
"lng" : -73.575107687761,
"type" : "MUSIC",
"userID" : "1373802105986614",
"visibility" : "Public"
},
"-Ko4cgP2rXJCIRBODWpm" : {
"Edate" : 523508400,
"Sdate" : 523497600,
"intersted" : 382,
"lat" : 45.4827983,
"lng" : -73.575107687761,
"type" : "MUSIC",
"userID" : "1373802105986614",
"visibility" : "Public"
}
}
}
在这种情况下,我会将信息放在单独的子节点中,但在 EventView 和 MapView 中都有同名的父节点。
【问题讨论】:
-
您能否提供示例代码以帮助我们简化您的查询。
-
您在问题中包含了 JSON 树的图片。请将其替换为实际的 JSON 作为文本,您可以通过单击 your Firebase Database console 中的导出 JSON 链接轻松获得。将 JSON 作为文本使其可搜索,让我们可以轻松地使用它来测试您的实际数据并在我们的答案中使用它,一般来说这只是一件好事。
-
@FrankvanPuffelen 我将图片更新为文字
-
使用 SDK 访问 Firebase 时,您总是要下载完整的节点。您不能向每个孩子请求“仅 MapView”。如果需要,请创建一个集合(即
MapViews),在其中仅保留地图视图数据。所以这最接近你的第二个结构。这种类型的数据扁平化是使用 Firebase 数据库时的常见建议,并且具有许多优点。
标签: ios firebase swift3 firebase-realtime-database