我的对象json是这样的:
var a = [{
"attributes": {
"Code": "SGL",
"Total": "811400"
},
"DayPrice": {
"Date": "2016-07-22",
"Rate": "811400"
}
}];
我想将DayPrice更改为这样的数组:
var a = [{
"attributes": {
"Code": "SGL",
"Total": "811400"
},
"DayPrice": [{
"Date": "2016-07-22",
"Rate": "811400"
}]
}];
有什么解决方案可以解决我的问题吗?
非常感谢你
最佳答案
您将需要遍历对象数组并将每个对象的DayPrice
属性包装在数组中,如下所示:
for (var i = 0; i < a.length; i++) {
a[i].DayPrice = [a[i].DayPrice];
}
Working example