如何遍历嵌套的JSON(firebase)?

时间:2018-09-29 21:20:43

标签: javascript json

这就是JSON的样子:

{
  "notes" : {
    "1DirZQovvSQjURmLH6FmSEIAeE52" : {
      "1529ee5f-7a45-40fc-ab11-740d1188e122" : {
        "color" : -2937041,
        "description" : "{\"note\":[{\"format\":\"HEADING\",\"text\":\"Jjk\"},{\"format\":\"TEXT\",\"text\":\"Z\"}]}",
        "folder" : "",
        "locked" : false,
        "pinned" : false,
        "state" : "TRASH",
        "tags" : "",
        "timestamp" : 1538123875034,
        "updateTimestamp" : 1538141384917,
        "uuid" : "1529ee5f-7a45-40fc-ab11-740d1188e122"
      },
  "7e11bb9b-d912-424f-b7c5-5e1d7124f5c8" : {
    "color" : -2937041,
    "description" : "{\"note\":[{\"format\":\"HEADING\",\"text\":\"Vhj\"}]}",
    "folder" : "",
    "locked" : false,
    "pinned" : false,
    "state" : "TRASH",
    "tags" : "",
    "timestamp" : 1538123812453,
     "updateTimestamp" : 1538141387318,
    "uuid" : "7e11bb9b-d912-424f-b7c5-5e1d7124f5c8"
  }
    }
  }
}

我是JS新手。在Java中,我可以为每个对象创建单独的JSONObject。

我确实检查了其他答案,但是它们显示了如何迭代:snapshot.val()['notes']['1DirZQovvSQjURmLH6FmSEIAeE52']['1529ee5f-7a45-40fc-ab11-740d1188e122']['color']

但是这么难编码。

如何使用索引或类似方法而不是通过键进行调用来检索所有键值对? 例如:
snapshot.val()[0][0][0][2]

编辑:为清楚起见添加了另一个json对象

0 个答案:

没有答案