var t={
"result": [
{
"series": "青春版",
"model": "G65Y"
},
{
"series": "青春版",
"model": "G55Y"
},
{
"series": "青春版",
"model": "G49Y"
},
{
"series": "青春版",
"model": "G43Y"
}
],
"flag": true,
"openid": "ovfA0uFwRR2tdS4qmD_nBvp4X1gA"
}
a(t);
function a(t) {//传入对象嵌套的数组 数组中嵌套着对象
for (var i in t) {//遍历对象)
if (t[i] instanceof Array) {//如果对象的value是属于数组类型的话
for (var d = 0; t[i].length; d++) {//循环数组 取出数组中的每一个对象
a(t[i][d])//然后把每个对象再重新递归遍历一遍
}
} else if (t[i] instanceof Object) {//如果遍历出来的不是数组是json对象的话从新递归
a(t[i])
} else if (typeof t[i] ==='string') {//走到最后这一步 如果得出来的value值是string 类型的话输出想要的value值
console.log(t["model"])
break;//结束循环
} else {
console.log('is not')
break;//结束循环
}
}
}
看看这个语句: