dto属性是boolean同时jsonstring结尾有\n会出现如下异常
解决方法:
1、dto属性采用boolean的 Package 类
2、jsonstring去掉结尾的"\n"
3、jsonstring采用字符串"false"去掉false
public class TestObj{
private b oolean res = false;
public boolean isRes() {
return res;
}
public void setRes(boolean res) {
this.res = res;
}
public static void main(String[] args) {
System.out.println(JSON.parseObject("{\"res\":false}\n",TestObj.class));
}
}```
异常如下:
Exception in thread "main" com.alibaba.fastjson.JSONException: unclosed.str
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:645)
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:591)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:442)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.parseRest(JavaBeanDeserializer.java:832)
at com.alibaba.fastjson.parser.deserializer.FastjsonASMDeserializer_1_TestObj.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:185)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:621)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:339)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:243)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:456)
at com.xiaojukeji.sec.mcs.api.common.TestObj.main(TestObj.java:22)
1条答案
按热度按时间4uqofj5v1#
版本号v1.2.31