这似乎是一个常见的问题,但我一生都无法找出我到底哪里出错了,我已经验证了我的 json 文件并且没有错误,我也可以发誓一切都在某个时候完美运行。我在一个文件夹中本地加载所有内容以下是我的 jquery 文件来加载我的 json 文件
$(document).ready(function() {
// loading json file
var catelogue;
var url = "shoppingItems.json";
$.getJSON(url, function(json) {
alert(json.shoppingItem[0].name);
});
});
这就是我的 json 文件的样子,是的,我去了http://jsonlint.com/进行验证
{
"shoppingItem": [
{
"name": "LG Tone",
"model_no": "HBS-730",
"type": "Bluetooth Stereo",
"price": "�45.00",
"stock": 10,
"images": "images/Headphones/lgtoneshbs.jpg"
},
{
"name": "NoiseHush",
"model_no": "NX22",
"type": "Wired Headphones",
"price": "�69.95",
"stock": 10,
"images": "images/Headphones/noisehushhead.jpg"
},
{
"name": "NoiseHush",
"model_no": "NX80",
"type": "Earphones",
"price": "�25.00",
"stock": 10,
"images": "images/Headphones/earpnoisehush.jpg"
},
{
"name": "Motorola MOTOROKR",
"model_no": "S305",
"type": "Bluetooth Stereo",
"price": "£35.00",
"stock": 10,
"images": "images/Headphones/earpnoisehush.jpg"
}
]
}
即使我尝试提醒 json 文件,也没有任何反应