Data parsing encountered a small problem, JSON format data multi-layer nesting, probably long so, in fact, the structure is more complex than this
Ex
{"
data": [
{
"criminal": [4,0,0,0,0,0,0,0,0,0,0,0],
"Fire": [0,0,0,0,0,0,0,0,0,0,0,0],
"Law and Order": [ 2,0,0,0,0,0,0,0,0,0,0,0],
"Traffic": [3,0,0,0,0,0,0,0,0,0,0,0],
"help": [2,0,0,0,0,0,0,0,0,0,0,0],
"other": [ 0,0,0,0,0,0,0,0,0,0,0,0]
},
{
"time": {
"date": +,
"Day": 5,
"hours":
" Minutes ":", "
month": One,
"seconds": "," Time
": 1513925906648,
" Timezoneoffset ": -480,
" Year ': 117
}
}
]
}
Want to traverse to get the array in the object:
In JavaScript, an array can be iterated, but the object is initially traversed with a for loop, showing the undefined;
Such as:
for (Var Key in res.data.data[0]) {
console.log (key+ ': ' +res.data.data[0]. Key);
}
And the following can be:
for (Var Key in res.data.data[0]) {
console.log (key+ ': ' +res.data.data[0][key]);
}
Another example:
var data ={
' Cloudy Day ': ', '
Sunny ': ' Bayi ',
' rainy Day ': ' A '
};
So: for
(var Key in data) {
Console.log (key+ ': ' +data[key]);
}
The above can be printed on the console:
Cloudy Day: 15
Sunny days: 81
Rainy Days: 12
and the following is not
for (var y in data) {
Console.log (y+ ': ' +data[y]);
}
Will print on the console:
Cloudy Day: Undefined
Sunny Day: undefined
Rainy Day: undefined