0

我有一个在 json 中输出关联数组的 php 代码。如何访问数组中的对象。我知道要访问我必须放入的 json 数组中的第一项,data.item0.adlink但我想遍历data对象并输出 json 数组中每个对象的所有内容。我的数组和代码如下。谢谢。

大批

{"item0":{"image":"preview.jpg","file":"video.mp4","adImage":"none","adLink":"http:\/\/sammyukavi.com\/"},"item1":{"image":"preview.jpg","file":"video.mp4","adImage":"none","adLink":"http:\/\/sammyukavi.com\/"},"item2":{"image":"preview.jpg","file":"video.mp4","adImage":"none","adLink":"http:\/\/sammyukavi.com\/"}}

代码

    $.ajax({
                        type: "GET",
                        dataType: "json",
                        data: {'first':'1','last':'3'} ,
                        beforeSend: function(x) {
                            if(x && x.overrideMimeType) {
                                x.overrideMimeType("application/json;charset=UTF-8");
                            }
                        },
                        url: 'test.php',
                        success: function(data) {
//I want to get a single item from the data object
                            $.each(data,function(){
//output a property for the single item here
console.log($(this))
                          })
                        }
                    })
                };
4

1 回答 1

0

这就是我一直在寻找的。

function(data) {
                        $.each( data, function( index, value ) {
                            console.log(value)
                        })
                    }
于 2013-03-14T08:27:56.057 回答