[英]Gson (Json) parse exception
使用Gson解析JSON时出现异常。
以下是例外:
com.google.gson.JsonParseException: The JsonDeserializer StringTypeAdapter failed to deserialize json object {"CGLIB$BOUND":true,"CGLIB$CONSTRUCTED":true,"CGLIB$CALLBACK_0":{"interfaces":[{}],"constructed":true,"persistentClass":{},"getIdentifierMethod":{"clazz":{},"slot":0,"name":"getmId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"modifiers":1,"annotations":[0,3,0,67,0,0,0,68,0,0,0,69,0,1,0,70,115,0,71],"root":{"clazz":{},"slot":0,"name":"getmId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"modifiers":1,"annotations":[0,3,0,67,0,0,0,68,0,0,0,69,0,1,0,70,115,0,71],"override":false},"override":false},"setIdentifierMethod":{"clazz":{},"slot":1,"name":"setmId","returnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"root":{"clazz":{},"slot":1,"name":"setmId","returnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"override":false},"override":false},"overridesEquals":false,"initialized":false,"entityName":"com.domain.Hotel","id":1,"unwrap":false},"mId":0,"mHotelLatitude":0.0,"mHotelLongitude":0.0,"mHotelRating":0.0,"mHotelAvgPrice":0.0} given the type class java.lang.String
JSON:
{
"CGLIB$BOUND": true,
"CGLIB$CONSTRUCTED": true,
"CGLIB$CALLBACK_0": {
"interfaces": [
{}
],
"constructed": true,
"persistentClass": {},
"getIdentifierMethod": {
"clazz": {},
"slot": 0,
"name": "getmId",
"returnType": {},
"parameterTypes": [],
"exceptionTypes": [],
"modifiers": 1,
"annotations": [
0,
3,
0,
67,
0,
0,
0,
68,
0,
0,
0,
69,
0,
1,
0,
70,
115,
0,
71
],
"root": {
"clazz": {},
"slot": 0,
"name": "getmId",
"returnType": {},
"parameterTypes": [],
"exceptionTypes": [],
"modifiers": 1,
"annotations": [
0,
3,
0,
67,
0,
0,
0,
68,
0,
0,
0,
69,
0,
1,
0,
70,
115,
0,
71
],
"override": false
},
"override": false
},
"setIdentifierMethod": {
"clazz": {},
"slot": 1,
"name": "setmId",
"returnType": {},
"parameterTypes": [
{}
],
"exceptionTypes": [],
"modifiers": 1,
"root": {
"clazz": {},
"slot": 1,
"name": "setmId",
"returnType": {},
"parameterTypes": [
{}
],
"exceptionTypes": [],
"modifiers": 1,
"override": false
},
"override": false
},
"overridesEquals": false,
"initialized": false,
"entityName": "com.domain.Hotel",
"id": 1,
"unwrap": false
},
"mId": 0,
"mHotelLatitude": 0,
"mHotelLongitude": 0,
"mHotelRating": 0,
"mHotelAvgPrice": 0
}
有谁知道为什么会出现这种异常?
问候
我可以获取要在Gson中解析的JSON。 当您在POJO中错误地将JSON属性类型映射到Java成员类型时,会产生上述错误(例如,在POJO中,JSON中的数组类型被声明为String类型)。
该错误是有点好奇我为GSON通常会从无法映射属性打印出来的JSON。 在您的情况下,这将是CGLIB$BOUND
,它是一个boolean
,但是Gson在这种情况下表现良好,为您提供了String
值"true"
。 如果您提供要反序列化的POJO,我们可以更准确地确定您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.