Json 错误com.fasterxml.jackson.databind.exc.MismatchedInputException:Cannot construct instance of

在把json数据转换成对象的时候出现这个错误

 

错误日志

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `实体对象` (although at least one Creator exists): no String-argument constructor/factory method to
 deserialize from String value ('{ "responses": { "logisticProviderID": "TTKD", "responseItems": { "response":{ "success": "true" } } } }')
 at [Source: (byte[])
""{ \"responses\": { \"logisticProviderID\": \"TTKD\", \"responseItems\": { \"response\": { \"success\": \"true\" } } } }""; line: 1, column: 1]

 

解决办法如下

  1. 比如说拿到json数据,包含有转义字符需要进行去掉转义字符,如下bs是json字符串
    StringEscapeUtils.unescapeJava(new String(bs, Charset.forName("utf-8")))
  2. 如果拿到的json数据字符串是 s1 外面多了一个 " "  需要去掉,用到如下方法
    byte[] bytes = s1.substring(1, s1.length() - 1).getBytes();
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页