我正在运行一个谷歌地方 api 我收到的响应是 json 格式我也在 json 查看器中检查了它,
{
"html_attributions" : [],
"next_page_token" : "CvQB7AAAAKcVCYUk92u8YbCxucwIYZZoVsNOAX1utAinxpRnjirhCWRGYI1ozjaw-9JauOVcr8iOqsvGVR3n183oJ-saMliylmFcPdJ8HwhIpxwWr8EsXDuTk4SCIYfSfcpSflBaWMqorPnNHAVMz9HS3r4q8Hq-UUobHHfD8HZ4auX9eOzVHETQezM0eT8164h1qsRChdvzEQdsxu1nze6c3GI6xO_PByuSeI8tksFlrPm2P45cZda-_qpQlmn_ksZiCzTRnpPGYG0U7AgtpoiUK85WTAX5CkH7jFpjYFap6LSSv33ujQtFFk52CECLu_iudN78IhIQri7z9TjtM4StCVCRS0Do6RoUrMm6kpd4rUbKD7LkTqbq3o7DOZU",
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.8599827,
"lng" : 151.2021282
},
"viewport" : {
"northeast" : {
"lat" : -33.8552624,
"lng" : 151.2031401
},
"southwest" : {
"lat" : -33.8657895,
"lng" : 151.2000123
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "92f1bbd4ecab8e9add032bccee40a57a8dfd42b4",
"name" : "Barangaroo",
"place_id" : "ChIJ1ZL9NkGuEmsRUEkzFmh9AQU",
"reference" : "CpQBhQAAAE4kOaitGfNEGHyhPnHMiP5NVmC9UsUYoYyOtBcO7zKBMNHR07V90Ohq6AV8qEWIAy0xpMvzlEimcdzW0KwdtCbUpWYKXFhby57oPCCUbMiIy_9yxPhtmnzcWFOMZqWWUnVxpYOW6hHR_JbLUbFRPZCSYqMJ9VL6xpxAbjulKVJFmJP4enq7MyeMe8rO0lJRCRIQelNwAky9wPZz9iyjcT7-UhoUGMbpbFWZZeZDjpOxJyipeWTTRxk",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"vicinity" : "Barangaroo"
}]
}
我以这种方式使用了模型 1.GooglePlacesModel 是包含列表结果的主模型;2.PlacesMainModel 包含List几何;我再次根据需要使用子模型现在我能够在结果数组中接收字符串字段,例如名称,图标,但是我无法接收几何字段,例如位置我遇到了以下堆栈跟踪
GooglePlacesModel plcModel = gson.fromJson(resultedPLaces, GooglePlacesModel.class);
where resultedPLaces is the json string as it is above,
googleapis.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@356dd6e9 failed to deserialized json object {"geometry":{"location":{"lat":-33.8599827,"lng":151.2021282}}} given the type com.google.gson.ParameterizedTypeImpl@53b59b06
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:63)
at com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
at com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:116)
at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:158)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
at com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
at com.google.gson.Gson.fromJson(Gson.java:568)
at com.google.gson.Gson.fromJson(Gson.java:515)
at com.google.gson.Gson.fromJson(Gson.java:484)
at com.google.gson.Gson.fromJson(Gson.java:434)
at com.google.gson.Gson.fromJson(Gson.java:406)
at com.webapp.actions.api.places.NearByPlacesAction.getNrByPlaces(NearByPlacesAction.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:140)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:158)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:101)