json作为ajax常用的一种数据类型,经常使用。但如果字段中出现换行符如何处理?
去掉显然不合适。有些字段本来就有换行符,如何能去掉?
测试一下json类的处理,也没有发现。想不到最终的处理确实如此简单:
后台代码把换行符\r\n替换为
\\r\\n,前台代码js收到的字符就是\r\n
例:将 字段值的内容为 mp3的lrc 文件中的内容 ,转换成 json 格式。
lrcc = a_lrc_content lrcc = replace(lrcc,"‘","\‘") lrcc = replace(lrcc,"\r\n","\\r\\n")
附: lrc 文件
[al:新概念英语(三)] [ar:MP3 同步字幕版(英音)] [ti:Too Early and Too Late] [by:更多学习内容,请到rrting.com搜索“新概念”] [00:01.47]Lesson 60 [00:03.41]Too early and too late [00:12.57]Why did the young girl miss the train? [00:17.81]Punctuality is a necessary habit in all public affairs in civilized society. [00:24.33]Without it, nothing could ever be brought to a conclusion; everything would be in a state of chaos. [00:32.73]Only in a sparsely-populated rural community is it possible to disregard it. [00:39.13]In ordinary living, there can be some tolerance of unpunctuality. [00:44.70]The intellectual, who is working on some abstruse problem, has everything coordinated and organized for the matter in hand.
时间: 2024-11-05 17:30:38