[英]jquery parse json data dynamically
我有这个json数据
{
"default": [
[
1325876000000,
0
],
[
1325876000000,
0
],
[
1325876000000,
0
],
[
1325876000000,
0
]
],
"direct": [
[
1328196800000,
0
],
[
1328196800000,
100
],
[
1328196800000,
0
],
[
1328196800000,
0
]
],
"Sales": [
[
1330517600000,
0
],
[
1330517600000,
0
],
[
1330517600000,
91
],
[
1330517600000,
0
]
],
"Support": [
[
1332838400000,
0
],
[
1332838400000,
0
],
[
1332838400000,
0
],
[
1332838400000,
0
]
]
}
我想将其更改为以下格式:
data = [{
label: 'defaul',
data: the array here
}, {
label: 'name',
data: the array here
}, {
label: 'name',
data: the array here
}, {
label: 'name',
data: the array here
}];
过去,我这样做是:
var thearray = result.default.
var theOtherArray = result.direct
...
..
and so on
之所以起作用,是因为我已经知道标签的名称。 我的意思是标签的名称是静态的。
但是现在它们是动态的,所以我不知道标签的名称。
我该怎么办?
我知道我必须用
var data = [];
$.each(result, function (index, value) {
var obj = {};
obj.label = SOMETHING
obj.data = result[label]
data.push(obj);
}
但是如何得到一些SOMETHING
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.