我有这个字符串:
'[{"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
}]
答案 0 :(得分:1)
这是一个JSON字符串,因此将其解析以获取对象
let str = '[{"name":"$1 Silver Membership Trial - Silver-Membership-3-Month","price":"279.88", "quantity":1}]';
console.log(JSON.parse(str) )