JSON parse error: Illegal unquoted character

文章讲述了同事在发布系统公告栏时遇到的HTTP400错误,原因是Fastjson在解析包含换行的字符串时出错。通过添加Fastjson依赖并配置application.yml允许特殊字符和转义,解决了这个问题。
摘要由CSDN通过智能技术生成

项目场景:

同事做一个系统发布一个 公告栏 格式如下:

xxx:
    xxxxxxx
          2024年3月

想把这一串字符提交到后端去解析


问题描述

后端出现返回错误码400并出现警告

Resolved [org.springframework.http.converter.HttpMessageNotReadabeException: 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<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 18]]

原因分析:

HTTP 400错误,也称为Bad Request错误,通常意味着服务器理解了请求,但由于请求的语法不符合规范,无法正常处理。
无法解析字符串中的换行


解决方案:

添加fastjson坐标
pom.xml

<dependency>
	<groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
</dependency>

允许特殊字符和转义符
application.yml

spring:
  jackson:
    parser:
      allow-unquoted-control-chars: true
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值