json的中換行符的處理

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.
相關文章
相關標籤/搜索