解决JSON解析报错JsonParseException_ Unrecognized token ‘zxx‘_ was expecting (‘true‘, ‘false‘ or ‘null‘)

Posted 谷哥的小弟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决JSON解析报错JsonParseException_ Unrecognized token ‘zxx‘_ was expecting (‘true‘, ‘false‘ or ‘null‘)相关的知识,希望对你有一定的参考价值。


版权声明

  • 本文原创作者:谷哥的小弟
  • 作者博客地址:http://blog.csdn.net/lfdfhl

问题描述

SpringBoot项目中使用jackson进行数据解析。

代码如下:

ValueOperations<String,String> valueOperations=stringRedisTemplate.opsForValue();
valueOperations.set("name","zxx");
String name=valueOperations.get("name");

报错如下:

Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'zxx': was expecting ('true', 'false' or 'null')

错误小结:

fasterxml无法解析该字符串。

原因剖析

jackson将zxx判断为了boolean类型,而不是字符串类型。

解决方案

将 “zxx” 改为 ““zxx”” 即可被jackson正确解析

以上是关于解决JSON解析报错JsonParseException_ Unrecognized token ‘zxx‘_ was expecting (‘true‘, ‘false‘ or ‘null‘)的主要内容,如果未能解决你的问题,请参考以下文章