行业知识
JSON转换异常:Cannot deserialize instance of `java.lang.String` out of START
2026-12-04 12:35:00
来源:互联网转载
问题与解决方案
问题
- 在日常开发当中我们往往会碰到很多调用第三接口的业务,那么就免不了各种 JSON 的转换,下面就来谈谈我遇到的这个问题
- 意思:就是说JSON解析失败,用String类型无法序列化Json对象
- 其实给出的提示已经很明确了:比如:Cannot deserialize instance of:无法反序列化,比如:through reference chain:指的就是这个参数的类型有问题,这里我这个 data 是一个 String 类型,但是三方返回的格式是这样的:{laoliu:xxxx}
HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token;nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 24] (through reference chain: xxxResponse["data"])
解决方案
- 于是乎:把这个字段改成了:Object,然后获取的时候再转换一下就可以了:JSONObject json=(JSONObject) JSONObject.toJSON(response.getData());
- 如果要获取里面的某个参数,可以这样:json.getString(“xxx”);
最新文章
- 小型商城源码,轻松搭建你的理想电商平台!
- 面面下载攻略,一步步轻松掌握下载技巧!
- 怎么自己架设蓝月传奇?
- WPS行距设置教程,轻松调整行距,掌握排版技巧!
- 揭秘大乐透复式中奖秘籍,计算规则与赢奖策略!
- 华为OD机试C卷-- 智能驾驶(Java & JS & Python & C)
- 【nacos启动错误】Server check fail, please check server localhost ,port 9848 is available , error ={}
- 服务器怎么加导入模组?
- 揭秘石油价格走势,揭秘波动背后的真相,洞悉未来预测!
- 浏览器怎么设置服务器地址?