像这样,如果你想访问 OrderItemId
var test = {"1":
[
{"OrderItemId":832,"ItemId":995,"Price":0},
{"OrderItemId":833,"ItemId":997,"Price":0},
{"OrderItemId":834,"ItemId":999,"Price":0}
],
"2":
[
{"OrderItemId":835,"ItemId":1008,"Price":0},
{"OrderItemId":836,"ItemId":1057,"Price":0}
]
}
alert(test["1"][0]['OrderItemId']);
alert(test["1"][1]['OrderItemId']);
alert(test["1"][2]['OrderItemId']);
alert(test["2"][0]['OrderItemId']);
alert(test["2"][1]['OrderItemId']);
更新,迭代未知长度的低谷测试
for (var i=0;i<test["1"].length;i++) {
alert(test["1"][i]['OrderItemId']);
}
这里有全自动枚举
var number, count = 0;
var en = [];
for(number in test) {
en[count]=number;
count++;
}
for (var r=0;r<en.length;r++) {
alert(en[r]);
for (var i=0;i<test[en[r]].length;i++) {
alert(test[en[r]][i]['OrderItemId']);
}
}