【问题标题】:How do I JSON.stringify( anObject ) without colons, backslashes, curly braces or quotes?如何在没有冒号、反斜杠、花括号或引号的情况下 JSON.stringify(an Object)?
【发布时间】:2013-12-06 07:30:24
【问题描述】:

This is a simple sentence. I don't want anything <form><b>but</b></form> this.

但是经过一些客户端 html 操作和...

var newBody = JSON.stringify(req.body);

随后更新了 MongoDb,

var update = { '$set' :{ 'body' : newBody} } 

我有这个:

body: '{"This is a simple sentence. I don\'t want anything <form><b>but</b></form> this. ":""}' 

当我将它转换回 html 时,它有花括号和引号,每次更新都会加剧这种情况。我看了here,并尝试了转义反斜杠,但我无法弄清楚。谢谢你。

{"{\"This is a simple sentence. I <form><b>don't</b></form> want this. \":\"\"}"}

【问题讨论】:

  • 试试escape(JSON.stringify(req.body))
  • 您能否详细说明一下您的设置以及您想要做什么?
  • 听起来你在 JSON 化 JSON .. 总而言之:不要。
  • 谢谢,但我得到了一些疯狂%in%ess ;)
  • 我正在尝试使用 html 操作字符串,而不是更新 mongodb 中的 html。当用户重新登录时,我希望更新的 html 替换旧的 html。

标签: javascript json node.js express stringify


【解决方案1】:

我相信 JSON.stringify 是不必要的,假设你传递了帖子参数simpleSentance= 'I dont want anything &lt;b&gt;but&lt;/b&gt; this'

var newBody = req.body.simpleSentance

【讨论】:

  • 我以为关键是body
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多