如何将嵌入的字符串数组转换为数组javascript

How to convert embedded string array into array javascript

我有一个字符串格式的数组。我如何将它转换为数组。

my_data="['A','B','C']"  (Note the quotes around [])
convert this to ['A','B','C']

到目前为止,我尝试了 json.parse 和其他字符串来排列对话,但没有成功。有人可以帮忙吗?

使用正则表达式将单引号替换为双引号,然后 JSON.parse 将正常工作:JSON.parse(my_data.replace(/\'/g,"\""));

单引号不是 JSON 数据的有效字符。