我正在使用简单的JSON Ajax请求来获取一些JSON数据。 但是,所有的时间,我尝试使用JSON对象,我得到了以下问题:简单请求:未捕获TypeError:无法读取未定义的属性“长度”
Uncaught TypeError: Cannot read property 'length' of undefined
$(document).on('pageinit', '#home', function() {
$.ajax({
url: "http://localhost/documents.json",
dataType: "json",
type: 'GET',
async: true,
success: function(result) {
//ajax.parseJSON(result);
$.each(result, function(idx, obj) {
alert(obj.name);
});
},
error: function(request, error) {
alert('Network error has occurred please try again!' + ' ' + request + ' ' + error);
}
});
});
我的JSON文件是有效的,看起来像这样:
{
"books": [{
"id": "01",
"name": "info",
"dateiname": "info.pdf"
}, {
"id": "02",
"name": "agb",
"dateiname": "agb.pdf"
}, {
"id": "03",
"name": "raumplan",
"dateiname": "raumplan.pdf"
}, {
"id": "04",
"name": "sonstiges",
"dateiname": "sonstiges.pdf"
}, {
"id": "05",
"name": "werbung",
"dateiname": "werbung.pdf"
}]
}
这是你的console.log成功的结果吗? – guradio
如何/你在哪里检查什么是“长度”? – Tushar
@Pekka是的,这是控制台输出。我没有检查任何东西。我只想解析JSON文件并将其添加到列表视图 – jublikon