报错org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: syntax error, expect {, actual int, pos 225, fastjson-version 1.2.69; nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual int, pos 225, fastjson-version 1.2.69
报错代码:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: syntax error, expect {, actual int, pos 225, fastjson-version 1.2.69; nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual int, pos 225, fastjson-version 1.2.69 at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.readType(FastJsonHttpMessageConverter.java:271) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: com.alibaba.fastjson.JSONException: syntax error, expect {, actual int, pos 225, fastjson-version 1.2.69 at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:503) com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:686) at com.alibaba.fastjson.JSON.parseObject(JSON.java:396) at com.alibaba.fastjson.JSON.parseObject(JSON.java:461) at com.alibaba.fastjson.JSON.parseObject(JSON.java:569) at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.readType(FastJsonHttpMessageConverter.java:263) ... 101 common frames omitted
报错原因:
1.传入的json数据有问题,跟接收类型不匹配。
- 建议重点检查传入的json数据与接受数据的类型。例如前端传进来的是String,后台接受的是Integer,这是最常犯的错误。
例如这里的roles是一个list,而前端返回的是一个Int
@Data
@ApiModel(description = "用户页面模型")
@EqualsAndHashCode(callSuper = true)
public class UserVO extends BaseVO {
@ApiModelProperty(value = "用户名", notes = "用户登录名", required = true)
private String username;
@ApiModelProperty(value = "密码", notes = "用户登录密码", required = true)
private String password;
@ApiModelProperty(value = "中文名")
private String chineseName;
@ApiModelProperty(value = "职位")
private String position;
@ApiModelProperty(value = "电话")
private String phone;
@ApiModelProperty(value = "邮箱地址")
private String mailAddress;
@ApiModelProperty(value = "组织架构id",example = "1")
private Integer organizationId;
private String organizationName;
@ApiModelProperty(value = "用户状态",example = "1")
private Integer status;
@ApiModelProperty(value = "手机号码",example = "0")
private String mobilePhone;
@ApiModelProperty(value = "性别", example = "1", notes = "M:男,W:女,S:秘密")
private Integer gender;
@ApiModelProperty(value = "身份证号码", example = "0")
private String identityCard;
@ApiModelProperty(value = "描述")
private String description;
@ApiModelProperty(value = "用户包含的角色信息集合")
private List<RoleVO> roles;
@ApiModelProperty(value = "是否初始化",example = "1",notes = "0:未初始化,1:已初始化")
private Long initialize;
}
前端JSON:roles是一个Int
-检查自定义类型是否与Json数据是否匹配,例如自定义类型里面还定义了一个对象,而返回来的json数据中不包含这个对象,这也是常犯的错误。
2.url地址写错了。
-有时候url地址写错了,也会报这个错误,不过比较少见