org.codehaus.jackson.JsonParseException:意外的字符(' '(代码65533/0xfffd)) [英] org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd))
问题描述
我在数据库中有一个Json字符串,但是在Java对象中进行转换时,会出现以下错误:
I have a Json string in the database but while converting in Java object, it gives following error:
由以下原因引起:org.codehaus.jackson.JsonParseException:意外的字符('.'(代码65533/0xfffd)):预期为有效值(数字,字符串,数组,对象,'true','false'或' null')
Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
Json是:{"crt":"wrd","name":"7|6A TTTM"}
在Java代码中,我已经对其进行了配置并将其设为私有(不是静态最终版本)
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);
注意::有时会转换对象中的Json字符串,但有时会出现上述错误.为什么会出现这种意外结果?
Note: It some time converts that Json string in Object but some time gives above error. Why this unexpected result comes?
推荐答案
这对我有用.
String formattedString = yourString.trim().replaceAll("\uFFFD", "");
这篇关于org.codehaus.jackson.JsonParseException:意外的字符(' '(代码65533/0xfffd))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!