Rumah > Soal Jawab > teks badan
{"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}
巴扎黑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);
}
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)
}
}
阿神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])
}
})
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);
})