我正在尝试将 json 解析为我的 java 对象,但我从 gson 收到错误。
错误是:
com.google.gson.JsonParseException: Expecting object found: "{ \"debug_info\" : [], \"html_attributions\" : [], \"results\" : [ { \"geometry\" : { \"location\" : { \"lat\" : 53.330661, \"lng\" : -6.265253 } }, \"icon\" : \"http://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png\", \"id\" : \"b50995ee5107706386c43d562fc614dc9db57937\", \"name\" : \"Lower Deck\", \"rating\" : 3.5, \"reference\" : \"CnRoAAAATUQrAt8LAzje_32Uzm5jklTmhsYA_orKtp9DIO_-kmCTU7DsHkNBae3aY9dLusdqJaSGwdj6G_-LpqbKWIi5r0RjcJWHljxCex8wI9UMO93uqSpr63S6qyNjJdw01nGEl1LLtbtz4VRGuKdEAl6sShIQEeM3-QnEjeoO7lEWZBYQQBoU0TOKwurVvTs565wKYPLQNmkLF5w\", \"types\" : [ \"bar\", \"establishment\" ], \"vicinity\" : \"1 Portobello Harbour, Dublin\" }, { \"geometry\" : { \"location\" : { \"lat\" : 53.332361, \"lng\" : -6.275473 } }, \"icon\" : \"http://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png\", \"id\" : \"8e8f338164d20d4ad7d943db980ce62d0325c2b5\", \"name\" : \"The Headline Bar\", \"rating\" : 3.6, \"reference\" : \"CnRvAAAAvlARk-Q-08T9kuvY_mp90vn10jf84TDNKymDtVyEYvt1wg7TEJyaqGF_R6zDGkXBoKSOEfovqm-A8w42OlOa1yAE-nMdGVgR_EKJKu5HHdzUmKlkFoPqcJxbJpFAblqCMz_ClpbwMEMtFNLA_hZidRIQVCg4_6vqhJuSDSqtbIG2zxoUeEGHiUYqFk2e_aB18dqFSKx_E5Y\", \"types\" : [ \"bar\", \"establishment\" ], \"vicinity\" : \"118 S Circular Rd, Crumlin, Dublin\" } ], \"status\" : \"OK\"}"
然后我的课程如下:
谷歌映射器
@SerializedName("debug_info")
private List<String> debug_info;
@SerializedName("html_attributions")
private List<String> html_attributions;
@SerializedName("next_page_token")
private String next_page_token;
@SerializedName("results")
private List<Results> results;
@SerializedName("status")
private String status;
结果
@SerializedName("geometry")
private Geometry geometry;
@SerializedName("icon")
private String icon;
@SerializedName("id")
private String id;
@SerializedName("name")
private String name;
@SerializedName("photos")
private Photos photos;
@SerializedName("rating")
private Double rating;
@SerializedName("reference")
private String reference;
@SerializedName("types")
private List<String> types;
@SerializedName("vicinity")
private String vicinity;
几何学
@SerializedName("location")
private Location location;
地点
@SerializedName("lat")
private Double lat;
@SerializedName("lng")
private Double lng;
相片
@SerializedName("height")
private int height;
@SerializedName("width")
private int width;
@SerializedName("html_attributions")
private List<String> html_attributions;
@SerializedName("photo_reference")
private String photo_reference;
最后,我正在尝试执行以下代码:
Gson gson = new GsonBuilder().serializeNulls().create();
String json = gson.toJson(retorno.toString());
GoogleMapper mapper = gson.fromJson(json, GoogleMapper.class);
拜托,有人可以帮助我吗?谢谢