【发布时间】:2009-04-06 21:47:16
【问题描述】:
我有以下 JSON:
{
"status" : "success",
"0": {
"link" : "test1",
"img" : "test2",
"title" : "test3"
},
"1":{
"link" : "test4",
"img" : "test5",
"title" : "test6"
}
}
显然 0 和 1 本身就是对象,我想要一种适当的方法来循环遍历该对象中的所有数据,即“状态”、“0”和“1”。我现在拥有的(和工作的)如下,我知道必须有一种更好的方法来查看元素是否只有一个深度,例如“状态”或者它是否是一个对象,例如“0”和“1” ':
// Prints the link from '0' and '1'
$.each(test, function(){
if(this == '[object Object]')
alert(this.link);
});
【问题讨论】: