如何将JSON转换为数组列表

我的JSON是Serie:

[{"Value":10,"ValuePourcent":2},{"Value":20,"ValuePourcent":3},{"Value":51,"ValuePourcent":1}]


我想要这种格式:

[[10,2],[20,3],[:51,1]]


到目前为止,这是我的代码:

var linq = Enumerable.From(rows);

var Serie = linq
                .GroupBy("$.Year", null,
                    function(key, g) {
                        var result = {
                            Value: g.Sum("$.Car"),
                            ValuePourcent: g.Sum("$.CarPourcent")/Total*100,
                        };
                        return result;
                    })
                .ToArray()

最佳答案

一个简单的for循环就能解决问题:



var data = [
  {"Value":10,"ValuePourcent":2},
  {"Value":20,"ValuePourcent":3},
  {"Value":51,"ValuePourcent":1}
];

var result = [];

for (var i = 0; i < data.length; i++) {
  var datum = data[i];

  result.push([datum.Value, datum.ValuePourcent]);
}

console.log(result);

关于javascript - 将JSON转换为数组列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31810674/

10-11 06:03