我的 JSON 响应值有单引号,但我想要双引号。我已经尝试过 JSON.stringfy()
和 JSON.parse()
,它们都不起作用。
响应:
[
{
title: 'Car',
price: 2323,
}
]
预期响应:
[
{
title: "Car",
price: 2323,
}
]
基本上,我想在 shopify graphql 查询中使用该响应。
mutation {
productCreate(input: {
id:"gid://shopify/Product/4725894742116"
title: "This is a car",
variants:[{
title:"car",
price: 12
}]
}) {
product {
id
}
}
}
最佳答案
您可以使用 JSON.parse() 方法解析一个 JSON 字符串 JSON.stringify() 方法将 JavaScript 对象或值转换为 JSON 字符串。
let obj =[
{
title: 'Car',
price: 2323,
}
];
let result = JSON.parse(JSON.stringify(obj));
console.log(result);
结果是
[
{
title: "Car",
price: 2323,
}
]
关于javascript - 用双引号替换 JSON 对象值单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62233942/