当前位置:   article > 正文

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

illegal unquoted character ((ctrl-char, code 10)): has to be escaped using b

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 依赖
  • 1
		<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.78</version>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
2、在配置文件中加入
  • 1
spring:
	jackson:
	    parser:
	      allow-unquoted-control-chars: true
  • 1
  • 2
  • 3
  • 4
3、重启项目、测试
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/332991
推荐阅读
相关标签
  

闽ICP备14008679号