遍历对象所有属性(json对象)
var response = { "status": 1, "message": "\u6210\u529f", "data": { "nowpage": 1, "totle_page": 1, "data": [ { "user_id": "11", "user_createdate": "2015-03-10 12:54", "user_phone": "18614088211", "user_status": "2", "last_logindate": "2015-03-10 12:55", "grade": "\u672a\u6388\u6743", "real_name": "", "remark": "\u6ca1\u94b1\u4e86", "user_status_name": "\u51bb\u7ed3" }, { "user_id": "11", "user_createdate": "2015-03-10 12:54", "user_phone": "18614088211", "user_status": "2", "last_logindate": "2015-03-10 12:55", "grade": "\u672a\u6388\u6743", "real_name": "", "remark": "\u6ca1\u94b1\u4e86", "user_status_name": "\u51bb\u7ed3" } ] } } for( a in response.data.data){ for( b in response.data.data[a]){ console.log(b + ' : ' + response.data.data[a][b]) } }
for( a in b )方法利用数组的形式可以在不知全部字段的情况下输出所有内容
b不同时,a的含义也不同。b是数组,a就是序号,b是对象,a就是键值,这里的a不管是序号还是键值,我们都可以灵活使用,判断、循环、输出,视情况而定