我正在尝试使用$ .getJSON在数组中存储一个值列表,但不知何故,它在数组中显示未在console.log中显示未定义
这是我的getJSON代码
jQuery.getJSON(List6.attractionimg, function(rf){
jQuery.each(rf, function(index, file){
attractionImgLinks.push(file.url);
});
JSON代码url“List6.attractionimg”正在给出
{"files":[{"name":"2013-11-17_183243.png","size":7975,"url":"http:\/\/example.com\/demo\/wp-content\/uploads\/rform\/attractionimg\/user5307eb38362d4\/2013-11-17_183243.png","thumbnailUrl":"http:\/\/example.com\/demo\/wp-content\/uploads\/rform\/attractionimg\/user5307eb38362d4\/thumbnail\/2013-11-17_183243.png","deleteUrl":"http:\/\/example.com\/demo\/wp-content\/themes\/driskill\/rform\/files\/attractionimg\/?file=2013-11-17_183243.png","deleteType":"DELETE"}]}
我在声明这段代码之外的数组就是问题吗?
答案 0 :(得分:1)
JSON是一个包含数组的files
属性的对象。尝试循环结果的files
属性...
jQuery.getJSON(List6.attractionimg, function(rf){
jQuery.each(rf.files, function(index, file){
attractionImgLinks.push(file.url);
});
答案 1 :(得分:0)
试试这个
$.each(rf.files,function(index,file){
attractionImgLinks.push(file.url);
})