我的 php 脚本中有 JSON 字符串,如下所示:
var r.co = {
"A20018425":[
{"balance":"1390.31"}, // 1
{"balance":"1304.11"}, // 2
{"balance":"1188.11"}, // 3
{"balance":"1421.71"} // 4
],
"A25005922":[
{"balance":"1000"}, // 1
{"balance":"1000.86"}, // 2
{"balance":"986.32"}, // 3
{"balance":"988.96"}, // 4
{"balance":"980.26"}, // 5
{"balance":"980.16"} // 6 MAX
],
"A25005923":[
{"balance":"1001"}, // 1
{"balance":"1000.16"}, // 2
]
}
我不知道有多少个 AXXXXXXXX 元素,它包含多少个元素。要获得 A 元素,我使用以下代码:
var accounts = [];
for(var key in r.co) {
if(r.co.hasOwnProperty(key)) {
accounts.push(key);
}
}
现在我知道我的 A 元素长度
var accounts_length = accounts.length; // 3 for example
现在我需要知道 A 中元素的最大长度:
var accounts_elements_length = [];
for (var c = 0; c < accounts.length; c++) {
accounts_elements_length.push(r.co[accounts[c]].length);
}
var accounts_elements_length_max = accounts_elements_length.max() // 6 For example
我怎样才能得到这个图表的输出数组?
var outputData = [{
count: 1,
A20018425: 1390.31,
A25005922: 1000,
A25005923: 1001
}, {
count: 2,
A20018425: 1304.11,
A25005922: 1000.86,
A25005923: 1000.16
}, {
count: 3,
A20018425: 1188.11,
A25005922: 986.32
}, {
count: 4,
A20018425: 1421.71,
A25005922: 988.96
}, {
count: 5,
A25005922: 980.26
}, {
count: 6,
A25005922: 980.16
}
}];
谢谢!