在我的网站中,我try 将字符串转换为包含换行符的JSON.
JSON.parse('{"hallo":"line1\r\nline2","a":[5.5,5.6,5.7]}');
这会产生"意外令牌"错误.我需要以某种方式逃避吗?
Yes, you should escape both \n and \r as they belong to the list of control characters. Full list of characters that need to be escaped can be found here. Your code would be
\n
\r
obj = JSON.parse('{"hallo":"line1\\r\\nline2","a":[5.5,5.6,5.7]}');
JSFiddle: link
Java核心技术面试精讲 -〔杨晓峰〕
Swift核心技术与实战 -〔张杰〕
图解 Google V8 -〔李兵〕
Go 并发编程实战课 -〔晁岳攀(鸟窝)〕
乔新亮的CTO成长复盘 -〔乔新亮〕
Spark核心原理与实战 -〔王磊〕
分布式金融架构课 -〔任杰〕
大厂广告产品心法 -〔郭谊〕
Vue 3 企业级项目实战课 -〔杨文坚〕
手把手教你落地DDD -〔钟敬〕
Python实战 · 从0到1搭建直播视频平台 -〔Barry〕
结构沟通力 -〔李忠秋〕
无涯教程 - Kotlin教程
无涯教程 - C语言教程
无涯教程 - Dart教程
无涯教程 - LinQ教程
无涯教程 - NativeScript教程
无涯教程 - Nginx教程
无涯教程 - R教程
无涯教程 - Python 渗透测试实战教程