代码改变世界

json中换行问题

2014-03-26 14:53  yangzaizai  阅读(1043)  评论(0编辑  收藏  举报

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"]

}