如何JSON.stringify(一个对象)没有冒号,反斜杠,花括号或引号?

时间:2013-12-06 07:30:25

标签: javascript json node.js express stringify

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时,它会有curley括号和引号,每次更新都会加剧。我看了here,并尝试了逃避反斜杠,但我无法理解。谢谢。

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

1 个答案:

答案 0 :(得分:0)

我认为JSON.stringify是不必要的,假设您传递了帖子参数simpleSentance= 'I dont want anything <b>but</b> this'

var newBody = req.body.simpleSentance