Rumah > Soal Jawab > teks badan
{
"data": {
"json1": [
{
"time": "05-17",
"msg": 0
},
{
"time": "05-18",
"msg": 2
}
],
"json2": [
{
"time": "05-17",
"msg": 0
},
{
"time": "05-18",
"msg": 2
}
],
"json3": [
{
"time": "05-17",
"msg": 0
},
{
"time": "05-18",
"msg": 2
}
]
}
}
请教下这样的数据如何循环
PHPz2017-04-10 15:25:53
js
function each(data, fn){ if(Object.prototype.toString.call(data) == '[object Array]'){ var l = data.length, i = 0; for(var i = 0, l = data.length; i < l; i++){ each(data[i], fn); } } else if(Object.prototype.toString.call(data) == '[object Object]'){ for(var prop in data){ each(data[prop], fn); } } else { fn(data); } } each(data, function(d){ console.log(d); })
PHP中文网2017-04-10 15:25:53
javascript
for(var i in json.data){ var arr = json.data[i]; if(arr.length){ for(var j=0;j<arr.length;j++){ // console.log(arr[j]) {time:"05-17",msg:2} } } }