{ "records": [ { "id": "744", "categoryname": "Floor Tiles", "photo": "", "width": "0", "height": "0", "secondlevelcategory": [ { "id": "833", "categoryname": "Digital Vitrified Tiles", "photo": "http://image.com", "width": "1031", "height": "700" } ] }, { "id": "744", "categoryname": "Floor Tiles", "photo": "", "width": "0", "height": "0", "secondlevelcategory": [ { "id": "833", "categoryname": "Digital Vitrified Tiles", "photo": "http://image.com", "width": "1031", "height": "700" } ] } ] } How can i Convert this Json response to Retrofit bean i am getting the Gson Error like Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
private void callCategoryApi() { Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(GithubUserAPI.CATEGORY_API) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); GithubUserAPI githubUserAPI = retrofit.create(GithubUserAPI.class); Call<List<CatResponseData>> call = githubUserAPI.getCategory(Utils.key); call.enqueue(this); } @Override public void onResponse(Call<List<CatResponseData>> call, Response<List<CatResponseData>> response) { int code = response.code(); if (code == 200) { List<CatResponseData> res = response.body(); for(CatResponseData resDat : res){ System.out.println("=== Response : " + resDat.getCategoryname()); } }else{ Toast.makeText(this, "Did not work: " + String.valueOf(code), Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<List<CatResponseData>> call, Throwable t) { System.out.println("=== Error : " + t.getMessage()); } and api call is
@POST("/apikey/{apikey}") Call<List<CatResponseData>> getCategory(@Path("apikey") String user); String CATEGORY_API = "https://api.callingservice.com";
please help me to solve this issue How can i Convert Json Response To Bean and My Bean class is like
public class CategoryBean { List<CatResponseData> responseData = new ArrayList<CatResponseData>(); } class CatResponseData { String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getCategoryname() { return categoryname; } public void setCategoryname(String categoryname) { this.categoryname = categoryname; } String categoryname; }