标准的json : let result=[{"a": 'aa', "b": 'aa', "c": 'aa'}, {"a": 'bb', "b": 'bb', "c": 'bb'}, {"a": 'cc', "b": 'cc', "c": 'cc'}];
非标准(我接到的数据): let json1=[{
"a": ['aa','bb','ccc'],
"b": ['aa','bb','ccc'],
"c": ['aa','bb','ccc']
}];
需求是格式化成标准数据(困扰的是怎么把数据循环出来,然后组合):
var nArr = []
var json1 = {
"a": ['aa','bb','ccc'],
"b": ['aa','bb','ccc'],
"c": ['aa','bb','ccc']
}
for (let i = 0; i < json1.a.length; i++) {
var cObj = {}
cObj.a = json1.a[i]
cObj.b = json1.b[i]
cObj.c = json1.c[i]
nArr.push(cObj)
}
console.log(nArr)