java 65533,org.codehaus.jackson.JsonParseException:意外字符(' '(代码65533/0xfffd))

博客内容讲述了在Java中从数据库获取Json字符串并转换为Java对象时遇到的错误:JsonParseException,原因是遇到了未知字符。作者提供了一个解决方案,即通过清理字符串中的特定字符解决问题。此问题有时会出现,有时不会,解决方案是使用正则表达式替换Unicode字符�。
摘要由CSDN通过智能技术生成

I have a Json string in the database but while converting in Java object, it gives following error:

Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

Json is : {"crt":"wrd","name":"7|6A TTTM"}

In java code I have configured it and have made it private (not static final)

objectMapper= new ObjectMapper();

objectMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);

Note: It some time converts that Json string in Object but some time gives above error. Why this unexpected result comes?

解决方案

this worked for me.

String formattedString = yourString.trim().replaceAll("\uFFFD", "");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值