如何從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 –