cari

Rumah  >  Soal Jawab  >  teks badan

javascript - js如何循环这样的json数据

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

请教下这样的数据如何循环
巴扎黑巴扎黑2819 hari yang lalu359

membalas semua(4)saya akan balas

  • 天蓬老师

    天蓬老师2017-04-10 15:25:53

    php$.each(arr.data,function(i,v){
    
        console.log(i,v);
    })
    

    balas
    0
  • PHPz

    PHPz2017-04-10 15:25:53

    jsfunction 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);
    })
    

    balas
    0
  • 阿神

    阿神2017-04-10 15:25:53

    for (var i in DATA)
    

    balas
    0
  • PHP中文网

    PHP中文网2017-04-10 15:25:53

    javascriptfor(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}
            }
        }
    }
    

    balas
    0
  • Batalbalas