我有一个JSON元素。 我需要获得每种交易类型的数量。当我尝试
var data = '{"2015:ATM01": {"volume": "2620000","count": "78"},"2015:PIN_PURCHASE01": {"volume": "5162305","count": "101"},"ALL:PIN_PURCHASE01": {"volume": "5162305","count": "101"},"ALL:DIRECT_DEPOSIT01": {"volume": "32752700","count": "50" }}';
var JSONArray=JSON.parse(data);
for(var k in JSONArray){
console.log("key is is.... "+k);
console.log("voulume is.... "+k.volume);
}
我将音量定义为未定义。请帮我。感谢。
答案 0 :(得分:1)
答案 1 :(得分:0)
k
是一个键(字符串),而不是一个对象。为了获得您想要的对象,您需要从JSONArray
获取值,如下所示:
var data = '{"2015:ATM01": {"volume": "2620000","count": "78"},"2015:PIN_PURCHASE01": {"volume": "5162305","count": "101"},"ALL:PIN_PURCHASE01": {"volume": "5162305","count": "101"},"ALL:DIRECT_DEPOSIT01": {"volume": "32752700","count": "50" }}';
var JSONArray=JSON.parse(data);
for(var k in JSONArray){
console.log("key is is.... "+k);
console.log("voulume is.... "+JSONArray[k].volume);
}