0

So this is how the JSON looks like:

{
  "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"
  }
    }
  }
}

I am new to js. In Java, I could create separate JSONObject for each.

I did check other answers but they show how to iterate like this: snapshot.val()['notes']['1DirZQovvSQjURmLH6FmSEIAeE52']['1529ee5f-7a45-40fc-ab11-740d1188e122']['color']

but this so much hard coding.

How do I retrieve all the key-value pairs using indices or something like that instead of calling by key? eg:
snapshot.val()[0][0][0][2]

Edit: added another json object for clarity

Lcukerd
  • 438
  • 6
  • 21
  • Not a duplicate. The inner JSON object(don't know what you call in js) is not an array so I cannot use indices as shown in that question. Also, 1529ee5f-7a45-40fc-ab11-740d1188e122 is generated unique everytime so I cannot use key name to retrive data. How do I do retrieve data? @Bergi – Lcukerd Sep 29 '18 at 21:30
  • Did you read the entire canonical answer, especially the part "*What if the property names are dynamic and I don't know them beforehand?*"? – Bergi Sep 29 '18 at 21:35

0 Answers0