Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将一个对象json转换为数组对象json?_Javascript_Jquery_Html_Arrays_Json - Fatal编程技术网

Javascript 如何将一个对象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

我的对象json如下所示:

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

我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。听着,我需要你的帮助。看这里: