Javascript 如何读取json数组?
如何读取此json数组?我得到了未定义的结果。我做错了什么 =jSON文件==Javascript 如何读取json数组?,javascript,json,Javascript,Json,如何读取此json数组?我得到了未定义的结果。我做错了什么 =jSON文件== // JSON { "items": [ { "title": "welcoem home", "author": "Charles Dickens" }, { "title": "Harry Potter", "author": "J rowling" }] } $(文档).ready(函数(){ $('#字母a')。单击(函数(){ $.getJSON('q3
// JSON
{
"items": [
{
"title": "welcoem home",
"author": "Charles Dickens"
},
{
"title": "Harry Potter",
"author": "J rowling"
}]
}
$(文档).ready(函数(){
$('#字母a')。单击(函数(){
$.getJSON('q3.json',函数(数据){
$(“#字典”).empty();
$.each(数据、函数(entryIndex、条目){
var html='';
html+=''+条目['title']+'';
html+=''+条目['author']+'';
html+='';
如果(条目['items']){
html+='';
$.each(条目['items'],函数(行索引,行){
html+=''+行+'';
});
if(条目['author']){
html+=''+条目['author']+'';
}
html+='';
}
html+='';
html+='';
$('#dictionary').append(html);
});
});
返回false;
});
});
json材料
不能在数据上运行每个,因为它不是数组。我想你想要的是
$.each(data.items, function(entryIndex, entry) {
错误在哪一行?既然我们能弄明白,为什么要让我们猜呢?谢谢。成功了。有没有其他不使用jquery的方法来完成这项工作-感谢您可以使用任何其他库/框架,或者自己用纯JavaScript编写所有代码。忽略AJAX获取部分,要迭代项,您可以使用for(var i=0;i
$.each(data, function(entryIndex, entry) {
$.each(data.items, function(entryIndex, entry) {