json转换异常

1、异常信息
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.util.LinkedHashMap: no String-argument constructor/factory method to deserialize from String value ('{"resCode":"99","resMsg":"登录超时,请重新登录","data":"登录过期"}')
at [Source: "{\"resCode\":\"99\",\"resMsg\":\"登录超时,请重新登录\",\"data\":\"登录过期\"}"; line: 1, column: 1]

2、产生原因
此时要装换为map的接送字符串值为:"{\"resCode\":\"99\",\"resMsg\":\"登录超时,请重新登录\",\"data\":\"登录过期\"}"
注意:此时改字符串的真正值为:这是value的显示:
[", {, \, ", r, e, s, C, o, d, e, \, ", :, \, ", 9, 9, \, ", ,, \, ", r, e, s, M, s, g, \, ", :, \, ", 登, 录, 超, 时, ,, 请, 重, 新, 登, 录, \, ", ,, \, ", d, a, t, a, \, ", :, \, ", 登, 录, 过, 期, \, ", }, "]
从value看,这个不是json字符串。

导致原因为:json2Map.get("result") 获取值为一个json字符串:{"resCode":"99","resMsg":"登录超时,请重新登录","data":"登录过期"},
@1处对该json字符串进行了又一次转换json操作,导致@2处无法转换为map,报异常
String obj2Json = JacksonUtil.Obj2Json(json2Map.get("result")); @1
Map<String, Object> json2Map2 = JacksonUtil.Json2Map(obj2Json);@2

猜你喜欢

转载自blog.csdn.net/m0_37948170/article/details/80381032
今日推荐