遍历json对象:
无规律:
有规律:
遍历json对象
有如下 json对象:
var obj ={"name":"冯娟","password":"123456","department":"技术部","sex":"女","old":30}
遍历方法:
数组对象的遍历:
下面我们对照一下js和jquer的遍历方法:
原文网址: https://www.cnblogs.com/qingqingzou-143/p/7079725.html
用 for in 循环 遍历
var str = '[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]'var xqo = eval('(' + str + ')')
for(var i in xqo){
alert(xqo[i].name)
}
var jsondata = yourdatafor(var x in jsondata){
document.write(x+"="+jsondata[x])
}
如果是jsonarray就外面套一层for即可
var jsonarray =yourarray
for(var i =0i<jsonarray.lengthi++){
var jsonobj = jsonarray[i]
for(var x in jsonobj){
document.write(x+"="+jsonobj[x])
}
}