我有以下数组:
var res = {
"status": "Success",
"data": [
{"assignedTo":"0", "createdDate":"23-07-2013", "count":"2"},
{"assignedTo":"182398", "createdDate":"01-08-2013", "count":"2"},
{"assignedTo":"182398", "createdDate":"23-07-2013", "count":"2"},
{"assignedTo":"182398", "createdDate":"24-07-2013", "count":"12"},
{"assignedTo":"182398", "createdDate":"22-07-2013", "count":"1"},
{"assignedTo":"182398", "createdDate":"30-07-2013", "count":"4"},
{"assignedTo":"182398", "createdDate":"31-07-2013", "count":"19"},
{"assignedTo":"185271", "createdDate":"24-07-2013", "count":"2"},
{"assignedTo":"185271", "createdDate":"23-07-2013", "count":"1"}
]
}
现在我想从上面创建一个 json 数组,其值为data
另一个 json,如下所示:
[
{
key: "0",
values: [["23-07-2013", 2]]
},
{
key: "182398",
values: [["01-08-2013", 2],
["23-07-2013", 2],
["24-07-2013", 12],
["22-07-2013", 1],
["30-7-2013", 4],
["31-7-2013", 19]
},
{
key: "185271",
values: [["24-07-2013", 2],
["23-07-2013", 1]
}
]
我试过如下:
for (i in res.data) {
for (k in res.data[i]) {
time_val += "[" + res.data[i]['createdDate'] + ","
+ res.data[i]['count'] + "],";
cumulative_val += '{key:"' + res.data[i]['assignedTo']
+ '",values:'+time_val+'},';
}
}
你能指导我怎么做吗?提前致谢。