我有一个格式为 JavaScript 的对象
{
"header": {
"dataFields": ["number", "name", "quantity", "id", "from"]
},
"data": [
"20|sam|12|2|2012-06-29T00:00Z|",
"18|peter|231|12|",
]
}
我正在尝试将其转换为这种格式:
[{"number" : "20", "name":"sam", "quantity" : "12", "id":"2"},
{"number" : "18", "name":"peter", "quantity": "231", "id" 12"}]
我不希望输出数组中的“字段”.. 实现它的最佳方法是什么?
var l={};
for ( var key in responseData.positions[i]){
l.name=key;
for(var k=0; k<responseData.positions.length;k++){
for ( var key in responseData.positions[k]) {
l.value= responseData.positions[k][key] ;
}
}
mainArray.push(l);