Rumah  >  Soal Jawab  >  teks badan

javascript - 这种后台获取的数据如何分别取出id

{"0":

{"id":1,"title":"1","content":"<p>1asdfasdf</p>","publisher":"3asdf ","views":0,"create_time":1490173181,"create_user":1,"status":0},

"1":{"id":2,"title":"2","content":"<p>asdfasdf</p>","publisher":"asdfadsf","views":0,"create_time":1490173186,"create_user":1,"status":0},
"2":{"id":3,"title":"3","content":"<p>2</p>","publisher":"3","views":0,"create_time":1490250129,"create_user":1,"status":0},"success":true}

大家讲道理大家讲道理2770 hari yang lalu260

membalas semua(4)saya akan balas

  • 巴扎黑

    巴扎黑2017-04-11 12:56:10

    var data = {"0":{"id":1,"title":"1","content":"<p>1asdfasdf</p>","publisher":"3asdf ","views":0,"create_time":1490173181,"create_user":1,"status":0},"1":{"id":2,"title":"2","content":"<p>asdfasdf</p>","publisher":"asdfadsf","views":0,"create_time":1490173186,"create_user":1,"status":0},"2":{"id":3,"title":"3","content":"<p>2</p>","publisher":"3","views":0,"create_time":1490250129,"create_user":1,"status":0},"success":true}}

    for(var i in data){

    console.log(data[i].id);

    }

    balas
    0
  • PHP中文网

    PHP中文网2017-04-11 12:56:10

    var jStr = {"0":{"id":1,"title":"1","content":"<p>1asdfasdf</p>","publisher":"3asdf ","views":0,"create_time":1490173181,"create_user":1,"status":0},"1":{"id":2,"title":"2","content":"<p>asdfasdf</p>","publisher":"asdfadsf","views":0,"create_time":1490173186,"create_user":1,"status":0},"2":{"id":3,"title":"3","content":"<p>2</p>","publisher":"3","views":0,"create_time":1490250129,"create_user":1,"status":0},"success":true}
        for(var i in jStr){
            if(jStr[i].id){
                console.log(jStr[i].id)
            }
        }

    balas
    0
  • 阿神

    阿神2017-04-11 12:56:10

    $.get('a.json',function (data,status) {
        console.log(data)
        for(var i=0;i<data.length;i++){
           console.log(data[i])
        }
    })

    balas
    0
  • ringa_lee

    ringa_lee2017-04-11 12:56:10

    例如:

    var arr = {"1":{"id":1,"name":"test"},"2":{"id":2,"name":"测试"}};
      $.each(arr,function(idx,item){    
       //输出
       alert(item.id+","+item.name);
    })

    balas
    0
  • Batalbalas