如何从 json 字符串中删除除第一个 json 值之外的双引号?

How to remove the double quotes from json string except the first json value?

请帮帮我。

这是我的 json 输入。

{"id":"FWAX014","price":18,"quantity":1}

预期输出应该是这样的:

{id:"FWAX014",price:18,quantity:1}

提前致谢。

以下正则表达式删除了您想要的双引号:

(?<={|,)"(\w+)"

See the demo

说明

  • (?<={|,) 检查以下模式前面是否有大括号或逗号
  • "(\w+)" 匹配引号之间的单词

示例

$re = '/(?<={|,)"(\w+)"/';
$str = '{"id":"FWAX014","price":18,"quantity":1}';

$result = preg_replace($re, '', $str);