cómo convertir json array a object json

Estoy usando Retrofit 2 en mi proyecto mi aplicación obtiene datos de las API de remolque api1 y api2

api1: –

[{"id":"29867","category_id":"31","author":"admins", "title":"hi","abstract":"","image_name":"","created":"11","body":"hi"}, {"id":"29866","category_id":"14","author":"admins", "title":"hi2","abstract":"","image_name":"img.png","created":"2017-11-16 16:02:00","body":"heloo"}] 

y api2: –

  [{"obj":"29867","category_id":"31","obj2":"admins", "title":"hi","abstract":"","image_name":"","created":"11","obj3":"hi"}, {"obj":"29866","category_id":"14","author":"admins", "obj2":"hi2","abstract":"","image_name":"Img.png","created":"2017-11-16 16:02:00","obj3":"Hello"}] 

Quiero hacer una class POJO para ambas API como

 class API_class{ var list:List<api1> =null var list2:List<pi2> =null } class api1{ @SerializedName("id") @Expose var id: Int? = null . . . } class api2{ @SerializedName("obj") @Expose var obj: Int? = null . . . } 

Intento algo como lo anterior pero no funciona para mí. Quiero hacer esto para poder usar una function de llamada como esta.

  retrofit.enqueue(object: Callback<API_class> { override fun onResponse(call: Call<API_class>?, response: Response<API_class>?) {. . . . } 

si el api1 y api2 era object Json como este

 {json:"ddd" [.....] } 

podré hacer mi idea, pero ahora es imposible

Si desea transformar su matriz json a un POJO, puede usar la dependencia de Gson

y testing este código a continuación:

  public static void main(String[] args) throws IOException { String json = "[{\"id\":\"29867\",\"category_id\":\"31\",\"author\":\"admins\",\n" + " \"title\":\"hi\",\"abstract\":\"\",\"image_name\":\"\",\"created\":\"11\",\"body\":\"hi\"},\n" + " {\"id\":\"29866\",\"category_id\":\"14\",\"author\":\"admins\",\n" + " \"title\":\"hi2\",\"abstract\":\"\",\"image_name\":\"img.png\",\"created\":\"2017-11-16 16:02:00\",\"body\":\"heloo\"}]"; Gson gson = new Gson(); Example yourObj[] = gson.fromJson(json, Example[].class); } 

El ejemplo POJO:

  @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ "id", "category_id", "author", "title", "abstract", "image_name", "created", "body" }) public class Example { @JsonProperty("id") private String id; @JsonProperty("category_id") private String categoryId; @JsonProperty("author") private String author; @JsonProperty("title") private String title; @JsonProperty("abstract") private String _abstract; @JsonProperty("image_name") private String imageName; @JsonProperty("created") private String created; @JsonProperty("body") private String body; @JsonProperty("id") public String getId() { return id; } @JsonProperty("id") public void setId(String id) { this.id = id; } @JsonProperty("category_id") public String getCategoryId() { return categoryId; } @JsonProperty("category_id") public void setCategoryId(String categoryId) { this.categoryId = categoryId; } @JsonProperty("author") public String getAuthor() { return author; } @JsonProperty("author") public void setAuthor(String author) { this.author = author; } @JsonProperty("title") public String getTitle() { return title; } @JsonProperty("title") public void setTitle(String title) { this.title = title; } @JsonProperty("abstract") public String getAbstract() { return _abstract; } @JsonProperty("abstract") public void setAbstract(String _abstract) { this._abstract = _abstract; } @JsonProperty("image_name") public String getImageName() { return imageName; } @JsonProperty("image_name") public void setImageName(String imageName) { this.imageName = imageName; } @JsonProperty("created") public String getCreated() { return created; } @JsonProperty("created") public void setCreated(String created) { this.created = created; } @JsonProperty("body") public String getBody() { return body; } @JsonProperty("body") public void setBody(String body) { this.body = body; } }