Ste*_*pan 2 android json gson retrofit
我是一名初学者,我在我的应用程序中使用Retrofit 2。我有这个JSON。(我尝试了很多解决方案,但没有任何对我有用)。感谢您的帮助
\n\n我遇到的错误:预期为 BEGIN_ARRAY,但在第 1 行第 2 列处为 BEGIN_OBJECT
\n\nJSON
\n\n{\n   responseCode: 1,\n   responseCodeText: "ok",\n   response: [\n      {\n         lat: 67.2422432322,\n         lng: 25.1441441441,\n         title: "Point na map\xc4\x9b 1",\n         desc: "Lorem ipsum dolor sit amet, consectetur adipisicing elit.\\nVero praesentium fugiat nobis pariatur cupiditate saepe dolorum, soluta dignissimos.",\n         photo: [\n            "http://photo3.jpg",\n            "http://photo4.jpg",\n         ]\n      },\n      {\n         lat: 39.1234787,\n         lng: 25.2242445,\n         title: "Point na map\xc4\x9b 2",\n         desc: "Possimus veritatis, neque a et odit ad itaque iusto asperiores perspiciatis voluptates,\\nvero praesentium fugiat nobis pariatur cupiditate saepe dolorum, soluta dignissimos.",\n         photo: [\n            "http://photo1.jpg",\n            "http://photo2.jpg",\n         ]\n      }, \n      //other\n界面
\n\npublic interface PointsInterface {\n\n        String BASE_URL = "MY_URL/";\n\n         @POST("getPointsOnMap")\n         Call<List<PointsOnMap>> getPointsOnMap();\n\n        class Factory {\n            private static PointsInterface service;\n\n            public static PointsInterface getInstance() {\n                if (service == null) {\n                    Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(BASE_URL).build();\n                    service = retrofit.create(PointsInterface.class);\n                    return service;\n                } else {\n                    return service;\n                }\n            }\n        }\n    }\nAPI调用
\n\n//api服务
\n\n   public void serviceInit() {\n        PointsInterface.Factory.getInstance().getPointsOnMap().enqueue(new Callback<List<PointsOnMap>>() {\n            @Override\n            public void onResponse(Call<List<PointsOnMap>> call, Response<List<PointsOnMap>> response) {\n                List<PointsOnMap> result = response.body();\n                Log.d("response", "Number of points received: " + result.size());\n            }\n\n            @Override\n            public void onFailure(Call<List<PointsOnMap>> call, Throwable t) {\n                Log.e("error", "Error");\n            }\n        });}\n模型
\n\npublic class PointsOnMap {\n\n    @SerializedName("lat") private Double lat;\n    @SerializedName("lng") private Double lng;\n    @SerializedName("title") private String title;\n    @SerializedName("desc") private String desc;\n\n    public PointsOnMap(Double lat, Double lng, String title, String desc) {\n        this.lat = lat;\n        this.lng = lng;\n        this.title = title;\n        this.desc = desc;\n    }\n\n    public Double getLat() {\n        return lat;\n    }\n\n    public void setLat(Double lat) {\n        this.lat = lat;\n    }\n\n    public Double getLng() { return lng; }\n\n    public void setLng(Double lng) {\n        this.lng = lng;\n    }\n\n    public String getTitle() { return title; }\n\n    public void setTitle(String title) {\n        this.title = title;\n    }\n\n    public String getDesc() {\n        return desc;\n    }\n\n    public void setDesc(String desc) {\n        this.desc = desc;\n    }\n}\n您的改造界面
     @POST("getPointsOnMap")
     Call<List<PointsOnMap>> getPointsOnMap();
应该
     @POST("getPointsOnMap")
     Call<PointsOnMapResponse> getPointsOnMap();
哪里PointsOnMapResponse
public class PointsOnMapResponse {
    @SerializedName("responseCode")
    long responseCode;
    @SerializedName("responseCodeText")
    String responseCodeText;
    @SerializedName("response")
    List<PointsOnMap> response;
    //getters, setters
}