$.getJSON("images/carouselPhotos.json", function(data) {
console.log(data);
});
这是我的json代码的样子,我的json文件如下所示
{photos :
[{photo : https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-frc1/480658_569309203089775_1014136234_n.jpg},
{photo : https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash4/422022_569309163089779_1265521956_n.jpg},
{photo : https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-snc6/270818_569309029756459_1227033818_n.jpg},
{photo : https://sphotos-a.xx.fbcdn.net/hphotos-ash3/575588_569308903089805_682444353_n.jpg},
{photo : https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-ash3/524702_569308839756478_866096962_n.jpg},
{photo : https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash4/420761_569308689756493_1009837829_n.jpg}]
}
我在任何地方都没有看到任何错误,但是对json文件的调用最终会出现在错误函数中。我能够在error.responseText中看到JSON数据。这是为什么?有人能让我知道我做错了吗?
谢谢
尼基尔
答案 0 :(得分:1)
JSON语法规定必须使用"
引用键和字符串,因此您的数据将为json
{
"photos": [
{
"photo": "https: //fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-frc1/480658_569309203089775_1014136234_n.jpg"
},
{
"photo": "https: //fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash4/422022_569309163089779_1265521956_n.jpg"
},
{
"photo": "https: //fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-snc6/270818_569309029756459_1227033818_n.jpg"
},
{
"photo": "https: //sphotos-a.xx.fbcdn.net/hphotos-ash3/575588_569308903089805_682444353_n.jpg"
},
{
"photo": "https: //fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-ash3/524702_569308839756478_866096962_n.jpg"
},
{
"photo": "https: //fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash4/420761_569308689756493_1009837829_n.jpg"
}
]
}
虽然你的网址是错误的,因为它们中有空格