JS端的:
var s = JSON.stringify(str);
var ss = s.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");
Server端的:
后台代码把换行符\r\n替换为\\r\\n,前台代码js收到的字符就是\r\n
return json.Replace("\r", "\\r").Replace("\n", "\\n");