Javascript 如何将一个对象json转换为数组对象json?
我的对象json如下所示:Javascript 如何将一个对象json转换为数组对象json?,javascript,jquery,html,arrays,json,Javascript,Jquery,Html,Arrays,Json,我的对象json如下所示: var a = [{ "attributes": { "Code": "SGL", "Total": "811400" }, "DayPrice": { "Date": "2016-07-22", "Rate": "811400" } }]; var a = [{ "attributes": { "Code": "SGL", "To
var a = [{
"attributes": {
"Code": "SGL",
"Total": "811400"
},
"DayPrice": {
"Date": "2016-07-22",
"Rate": "811400"
}
}];
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"
}
}];
var a = [{
"attributes": {
"Code": "SGL",
"Total": "811400"
},
"DayPrice": [{
"Date": "2016-07-22",
"Rate": "811400"
}]
}];
有什么办法解决我的问题吗
非常感谢将带有属性的数组分配给属性
a[1].DayPrice = [a[1].DayPrice];
或者使用循环:
var a=[{“attributes”:{“code”:“SGL”,“Total”:“811400”},“DayPrice”:{“Date”:“2016-07-22”,“Rate”:“811400”}];
a、 forEach(函数(a){
如果(a中的“日价格”){
a、 DayPrice=[a.DayPrice];
}
});
document.write(''+JSON.stringify(a,0,4)+'')代码>将带有属性的数组分配给属性
a[1].DayPrice = [a[1].DayPrice];
或者使用循环:
var a=[{“attributes”:{“code”:“SGL”,“Total”:“811400”},“DayPrice”:{“Date”:“2016-07-22”,“Rate”:“811400”}];
a、 forEach(函数(a){
如果(a中的“日价格”){
a、 DayPrice=[a.DayPrice];
}
});
document.write(''+JSON.stringify(a,0,4)+'')代码>希望这会有所帮助
for (var i = 0; i < a.length; i++) {
a[i].DayPrice = [a[i].DayPrice];
}
检查此项希望有帮助
for (var i = 0; i < a.length; i++) {
a[i].DayPrice = [a[i].DayPrice];
}
选中此项您需要在对象数组中循环,并将每个对象的DayPrice
属性包装在一个数组中,如下所示:
for(变量i=0;i
您需要在对象数组中循环,并将每个对象的DayPrice
属性包装在一个数组中,如下所示:
for(变量i=0;i
我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。看这里: