我有一个在 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))
})
}
})
};