首页 前端知识 JSON parse error: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backsla

JSON parse error: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backsla

2024-05-10 08:05:44 前端知识 前端哥 516 637 我要收藏

JSON parse error: Illegal unquoted character ((CTRL-CHAR, code 10)):
has to be escaped using backslash to be included in string value;
nested exception is
com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted
character ((CTRL-CHAR, code 10)): has to be escaped using backslash to
be included in string value\n at [Source: (PushbackInputStream);

百度翻译如下

JSON解析错误:非法的无引号字符((CTRL-CHAR,代码10):必须使用反斜杠进行转义才能包含在字符串值中;嵌套异常为com.fasterxml.jackson.databind.JsonMappingException:非法的无引号字符((CTRL-CHAR,代码10):必须使用反斜杠进行转义,才能包含在[Source:(PushbackInputStream);

出现原因:Json 字符中有有些字段比如空格、反斜杠、换行符等一些特殊字符,但是 Json 框架没有对这些字符进行处理,就会导致出现错误。

SpringBoot项目解决方法

1、首先加入 fastjson 依赖
		<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.78</version>
        </dependency>
2、在配置文件中加入
spring:
	jackson:
	    parser:
	      allow-unquoted-control-chars: true
3、重启项目、测试
转载请注明出处或者链接地址:https://www.qianduange.cn//article/7914.html
标签
maven
评论
会员中心 联系我 留言建议 回顶部
复制成功!