json - 将对象 ID 分配给 Firebase 中导入的 JSON 的方法

标签 json firebase firebase-realtime-database

Firebase 按以下方式组织导入的 JSON 文件:

Firebase database view

但是导入的文件(以及从 Firebase 导出的文件)是这样组织的:

 {
  "features" : [ {
    "geometry" : {
      "coordinates" : [ -77.347191, 36.269321 ],
      "type" : "Point"
    },
    "properties" : {
      "name" : "Branch Chapel",
      "osm_id" : "262661",
      "religion" : "christian"
    },
    "type" : "Feature"
  },
...

Firebase 似乎为“功能”数组中的每个对象分配了一个内部编号。这很好,但是在不知道 Firebase 如何命名的情况下很难引用每个对象 - 而且我有 40 万多个对象。

有没有办法为每个对象分配一个 ID 以防止 Firebase 生成自己的 ID?或者有没有办法在导入数据后以编程方式重命名/重新组织数据?最佳结果是对象由其 osm_id 命名,而不是 Firebase 分配的任意数字。

感谢任何帮助。

最佳答案

去掉方括号并用花括号代替

这个

{
    "flags": {
        "1": {
            "information": "blah",
        },
        "2": {
            "information": "It is great!",
        },
        "3": {
            "information": "Amazing!",
        }
    }
}

不是这个

[
    {
        "1": {
            "information": "blah",
        }
    },
    {
        "2": {
            "information": "It is great!",
        }
    },
    {
        "3": {
            "information": "Amazing!",
        }
    }
]

关于json - 将对象 ID 分配给 Firebase 中导入的 JSON 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42379731/

相关文章:

javascript - 如何在firebase auth中更改电子邮件?

angular - 删除实时firebase数据库中的数据: messages of a certain user and the user itself

javascript - React.js 从特定行检索数据

javascript - 如何将 Javascript 对象的内容复制到空对象中?

android - 将 JSON 字符串解析为 Kotlin Android 中的对象列表(MOSHI?)

javascript - react GitHub repo API

node.js - 如何订购一个 firebase 集合,然后向每个文档写入一些内容?

javascript - AWS Lambda & JSON.stringify\\n ->\n - 不适用于 Slack API

firebase - 在 Firebase 托管中哪里可以找到之前连接的自定义域的 DNS A 记录信息?

swift - Firebase,检索数据 : Find all Titles that have 'Status' as 'Open' in Swift