Jquery删除""来自json值

时间:2016-02-03 10:54:19

标签: jquery json

我有以下Json值:

["{"label":"0-30 Days","value":"0.00"}", "{"label":"30-60 Days","value":"0.00"}", "{"label":"60-90 Days","value":"0.00"}", "{"label":"90-180 Days","value":"50,764,332.30"}"]

如何删除""从数据,以便我保持以下语法?

[{"label":"0-30 Days","value":"0.00"},{"label":"30-60 Days","value":"0.00"}, {"label":"60-90 Days","value":"0.00"},{"label":"90-180 Days","value":"50,764,332.30"}]

1 个答案:

答案 0 :(得分:0)

假设你有一个包含4个字符串的数组,你可以试试这个:

var someArray = [
    '{"label":"0-30 Days","value":"0.00"}', 
    '{"label":"30-60 Days","value":"0.00"}', 
    '{"label":"60-90 Days","value":"0.00"}', 
    '{"label":"90-180 Days","value":"50,764,332.30"}'
];

var someJson = [];

someArray.forEach(function(item) {
    someJson.push(JSON.parse(item));
});

console.log("JSON", someJson);

或者您可以更改原始数组:

for(var i = 0; i < someArray.length; i++) {
    someArray[i] = JSON.parse(someArray[i]);
}

console.log("Array", someArray);

不过,我不确定这是不是你想要的。