如何从数据中删除双引号
[{"label":"Ravi Kanti","data":"[314,444]"},{"label":"Amit prakash","data":"[78]"},{"label":"Roshan Kumar","data":"[215,80,165]"}]
由于数据值在双引号内,即“ [314,444]” 如何删除双引号
答案 0 :(得分:1)
不多,因为它只是嵌入式JSON:
data = [{"label":"Ravi Kanti","data":"[314,444]"},{"label":"Amit prakash","data":"[78]"},{"label":"Roshan Kumar","data":"[215,80,165]"}]
data.forEach(entry => {
entry.data = JSON.parse(entry.data)
});
JSON.stringify(data)
// [{"label":"Ravi Kanti","data":[314,444]},{"label":"Amit prakash","data":[78]},{"label":"Roshan Kumar","data":[215,80,165]}]
答案 1 :(得分:0)
在Javascript中,您可以这样尝试:
var str = '[{"label":"Ravi Kanti","data":"[314,444]"},{"label":"Amit prakash","data":"[78]"},{"label":"Roshan Kumar","data":"[215,80,165]"}]';
var arr = JSON.parse(str, function (key, value) {
if (key === "data") {
return JSON.parse(value);
} else {
return value;
}
});
console.log(arr);