如何从jquery中获取json数组对象的所有数据?
我已经尝试过,但我的代码只能从json对象获取数据。如何使用JQUERY从JSON数组对象获取数据?
这是我的JSON文件student.json:
{"status":true,
"offset":0,
"limit":25,
"total":2,
"data":[
{ "id":231,
"title":"mytitle1",
"content":"myconten1",
"created_at":"2017-07-10 03:56:32",
"updated_at":"2017-07-10 03:56:32"
},{ "id":230,
"title":"mytitle2",
"content":"mycontent2",
"created_at":"2017-07-10 03:56:06",
"updated_at":"2017-07-10 03:56:06"
}]}
我的js脚本:
<script>
$(document).ready(function(){
$(function(){
var $orders = $('#orders');
$.ajax({
type: 'GET',
url: 'json/student.json',
success: function(data) {
console.log('success', data);
$.each(data, function(i, dataentry){
$orders.append('<li>dataid: '+dataentry.id+'</li>');
});
}
});
});
});
</script>
你的意思是你的Ajax调用失败? –
您应该了解JSON和JS中的对象字面量之间的区别。 – lexith
我认为它shoild是:data.data [0] .id –