【问题标题】:Restructuring JSON to use with Firebase Realtime Database重构 JSON 以与 Firebase 实时数据库一起使用
【发布时间】:2019-10-23 20:46:27
【问题描述】:

我目前有一个这样结构的 JSON 文件

[
 {
    "firstKey": {
        "item": "string",
        "item2": "string",
        "item3": "string"
    }
 },
 {
    "secondKey": {
        "item": "string",
        "item2": "string",
        "item3": "string"
    }
 }, 
.
.
.

]

有没有办法改成

 "firstKey": {
  "item": "string",
  "item2": "string",
  "item3": "string"
},
"secondKey": {
  "item": "string",
  "item2": "string",
  "item3": "string"
},
.
.
.

这样我就可以直接将其复制到我的 JSON 并将其导入 Firebase 实时数据库。

【问题讨论】:

    标签: javascript json firebase firebase-realtime-database


    【解决方案1】:

    我认为不建议您将其更改为第二种格式。您可以首先映射数组并将值插入到您的 firebase 数据库中。

    例子:

    const my_array = [
     {
        "Key": {
            "item": "string",
            "item2": "string",
            "item3": "string"
        }
     },
     {
        "Key": {
            "item": "string",
            "item2": "string",
            "item3": "string"
        }
     }
    ]
    
    
    my_array.map((value)=>{
     //you can now insert value into your database 
    })
    
    

    【讨论】:

      猜你喜欢
      • 2018-05-07
      • 2022-01-03
      • 1970-01-01
      • 2020-03-31
      • 2021-11-24
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多