如何删除双引号

时间:2019-03-01 19:19:40

标签: node.js

如何从数据中删除双引号

[{"label":"Ravi Kanti","data":"[314,444]"},{"label":"Amit prakash","data":"[78]"},{"label":"Roshan Kumar","data":"[215,80,165]"}]

由于数据值在双引号内,即“ [314,444]” 如何删除双引号

2 个答案:

答案 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);