我正在尝试通过 jquery 加载本地 JSON 文件。代码工作正常,但数据在数组中不可用。
$.getJSON("/ajax/data/myjasonfile.json", function(json) {
console.log(json);
});
我的控制台仅显示
Object {data: Array[1]}
我的示例 json
{
"data": [
{
"number": "1234",
"nameOne": "Laten Thamn",
"type": "Fishing Vessels",
"flagName": "5467",
"buildDate":"12/08/2016"
}
]
}
尝试这样做来了解您的响应结构。
$.getJSON("myjasonfile.json", function(json) {
console.log(json); // access the response object
console.log(json.data); // access the array
console.log(json.data[0]); // access the first object of the array
console.log(json.data[0].number); // access the first object proprty of the array
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)