我创建了一个对象..请告诉我如果我做得对:
{"images": {
image1 : {
"small_image" : "images/1.png",
"large_image" : "images/big/1.png"
},
image2 : {
"small_image" : "images/2.png",
"large_image" : "images/big/2.png"
},
image3 : {
"small_image" : "images/3.png",
"large_image" : "images/big/3.png"
},
}
现在,我用名称 images.json
保存了它如何使用jQuery在我的HTML文件中调用它?.. 我想先在控制台上测试它..
我使用此代码并且它不会在控制台上显示anthing ..
$.getJSON("js/images.json", function(data){
$.each(data, function (index, value) {
console.log("asdfasdf " +value);
});
});
答案 0 :(得分:2)
您需要修改对象Literal以使其成为JSON字符串。看起来应该更像这样:
{"images": {
"image1" : {
"small_image" : "images/1.png",
"large_image" : "images/big/1.png"
},
"image2" : {
"small_image" : "images/2.png",
"large_image" : "images/big/2.png"
},
"image3" : {
"small_image" : "images/3.png",
"large_image" : "images/big/3.png"
}
}}
假设您的网络服务器设置为正确提供.json文件,那么您已经拥有的javascript应该可以使用。