I've been developing a web application where I'm receiving data in this format, from a node server:
"{""elements":[{"10sr2b2":{"total":0,"bad":22,"clients":["fc8e7f","fc8e7e"],"zone":"101900"}}]}"
The poblem is this data is an array key-value called "elements" where "10sr2b2" is the key of the first element of the array.
So when I call $.parseJSON() method, this return an object like this:
elements: Array[1]
0: Object
10sr2b2: Object
zone: "101900"
clients: Array[2]
0: "fc8e7f"
1: "fc8e7e"
length: 2
__proto__: Array[0]
bad: 22
total: 0
Where "10sr2b2" it's supposed to be the key and it's an object and I need to get this value somehow.
Can you help me?
Object {"key": Array [Object {"key": Object {...}}]}just as you're seeing when you parse it. Whilst you can get find keys in Objects, it might suit your needs better to re-structure what the server is giving you intoObject {"key": Array [Object {"key": "hash", "value": Object {...}}]}, and now you can useo.elements[i].key;ando.elements[i].value