要从字符串数组中删除单引号

时间:2019-12-29 12:24:41

标签: javascript json

我有这个字符串:

'[{"name":"$1 Silver Membership Trial - Silver-Membership-3-Month","price":"279.88", "quantity":1}]'

我想将其格式化为:

[{
  "name": "$1 Silver Membership Trial - Silver-Membership-3-Month",
  "price": "279.88",
  "quantity": 1
}]

[{
  'name': '$1 Silver Membership Trial - Silver-Membership-3-Month',
  'price': '279.88',
  'quantity': 1
}]

1 个答案:

答案 0 :(得分:1)

这是一个JSON字符串,因此将其解析以获取对象

let str = '[{"name":"$1 Silver Membership Trial - Silver-Membership-3-Month","price":"279.88", "quantity":1}]';

console.log(JSON.parse(str) )