Crane Perch Villa

Using no way as way,
having no limitation as limitation.


  • 首页

  • 分类

  • 归档

  • 关于

如何将 json 对象字符串 key 的引号去掉

发表于 2021-09-20 | 分类于 技术分享
1
2
3
4
5
6
7
function formatJson(str) {
return str.replace(/"(\w+)"(\s*:\s*)/g, '$1$2')
}

const json = '{"a": "a","b": "b","c": "c"}'

console.log(formatJson(json)) // {a: "a",b: "b",c: "c"}

终于找到一个简洁完美的去掉 json key 引号 的正则。

123…33
wuyaoxing

wuyaoxing

Keep the heart of the empty spirit,
invisible,
can't,
just like water.

33 日志
9 分类
19 标签
GitHub
© 2021 wuyaoxing
由 Hexo 强力驱动
|
主题 — NexT.Pisces