json字符串中不能出现换行符\n等字符串,因此需要对他们进行处理,再发送给Server。处理方式如下:
var myJSONString = JSON.stringify(myJSON);
var myEscapedJSONString = myJSONString.replace(/\\n/g, "\\n")
.replace(/\\'/g, "\\'")
.replace(/\\"/g, "\\\"")
.replace(/\\&/g, "\\&")
.replace(/\\r/g, "\\r")
.replace(/\\t/g, "\\t")
.replace(/\\b/g, "\\b")
.replace(/\\f/g, "\\f");
// myEscapedJSONString is now ready to be POST'ed to the server.
本文详细阐述了如何在JSON字符串中处理换行符、特殊字符,并将其安全地发送到服务器的方法。
128

被折叠的 条评论
为什么被折叠?



