【问题标题】:Jquery.getjson is unable to store value in an arrayJquery.getjson 无法将值存储在数组中
【发布时间】:2014-02-23 19:42:24
【问题描述】:

我正在尝试使用 $.getJSON 将值列表存储在数组中,但不知何故它无法解决数组在 console.log 中显示未定义

这是我的 getJSON 代码

jQuery.getJSON(List6.attractionimg, function(rf){
                jQuery.each(rf, function(index, file){
                    attractionImgLinks.push(file.url);
                }); 

URL“List6.attractionimg”给出的 JSON 代码

{"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"}]}

我在这段代码之外声明数组是这里的问题吗?

【问题讨论】:

    标签: jquery json getjson


    【解决方案1】:

    JSON 是一个具有files 属性的对象,其中包含一个数组。尝试循环结果的files 属性...

    jQuery.getJSON(List6.attractionimg, function(rf){
                    jQuery.each(rf.files, function(index, file){
                        attractionImgLinks.push(file.url);
                    }); 
    

    【讨论】:

      【解决方案2】:

      试试这个

      $.each(rf.files,function(index,file){
       attractionImgLinks.push(file.url);
      })
      

      【讨论】:

        猜你喜欢
        • 2013-09-29
        • 1970-01-01
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        • 2020-11-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多