json中换行问题

时间:2021-04-24 21:13:24

json中不能存在换行,但可以进行替换后给服务器

function(text_info)
{

text_info=text_info.replace(/\r/gm,"<br\>")
text_info=text_info.replace(/\n/gm,"<br\>")//进行替换

text_info = JSON.parse(text_info)
console.log(text_info)
//alert(text_info)
text = text_info["text"]
text=text.replace(/<br\>/gm, "\n")//反替换
text_style = text_info["style"]

}