简体   繁体   English

如何将数组转换为json对象数组?

[英]How to convert array to json object array?

I have the array in the following pattern:我有以下模式的数组:

[["abc","def"],["dss","ddd"]]

I need to convert it into an array of json objects:我需要将其转换为 json 对象数组:

[{"wf":"abc","sb":"def"},{"wf":"dss","sb":"ddd"}]

How would I do this?我该怎么做?

Try this尝试这个

var data= [["abc","def"],["dss","ddd"]];
var json = data.map(function (value, key) {
    return {
        "wf": value[0],
        "sb": value[1]
    }
});
console.log(json);
console.log(JSON.stringify(json)); // need string

DEMO演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM