第一种json结构:
var jsongood = {"goods":[{"parentId":"null","productId":1,"name":"商品","amount":"null"},{"parentId":1,"productId":11,"name":"水果","amount":"null"}]};
遍历的方法是:
for(var i = 0;i < jsongood.goods.length; i ++){ alert(jsongood.goods[i].amount);}
第二种json结构:
var jsongood = {"parentId":"null","productId":1,"name":"商品","amount":"null"}
遍历方法:
function getJsonLength(jsonobj){ var length = 0; for(var i in jsonobj){ length ++; } return length; } getJsonLength(jsongood)