【问题标题】:Javascript JSON parse unescape quotes?Javascript JSON解析转义引号?
【发布时间】:2015-10-16 21:52:00
【问题描述】:

我有一个用户输入了 JSON 数据,然后将其保存到其他对象。但我得到的不是 JSON,而是 dtExport: '{\\"type\\":\\"polyline\\"}

我该如何解决? 谢谢。

【问题讨论】:

  • 请贴出有问题的代码。

标签: javascript json escaping


【解决方案1】:

var x = '{\"type\":\"polyline\"}'; x = x.replace(/\"/g, "\"");

和下一个 JSON.parse

结果:

"{"type":"polyline"}"

【讨论】:

  • 不起作用 :( 我有var planJson = JSON.parse(message.text) 然后保存到数据库:db.merge('plans', planId, { "dtExport": JSON.stringify(planJson) }) 但还是一样。
  • @fivepointseven 我的答案已由 Mateusz 编辑,现在似乎工作正常。
猜你喜欢
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 2019-10-14
  • 1970-01-01
  • 2017-07-10
  • 1970-01-01
  • 2021-11-11
  • 1970-01-01
相关资源
最近更新 更多