Я очень медленный и не могу понять, как я могу инициализировать, что я вхожу в объект, затем в массив.Я пытался сделать новый Gson из компонентов, но я не знаю как.Должен ли я создать новый класс внутри модели, это также массив?И затем выполните <ArrayList<Component.Components(inside class)>>
?
Модель
public class Component {
@SerializedName("total")
transient private Integer total;
@SerializedName("rows")
private ArrayList<Rows> rows;
public class Rows {
@SerializedName("name")
private String name;
@SerializedName("image")
private String image;
@SerializedName("serial")
private String serial;
@SerializedName("purchase_cost")
private String cost;
public Rows(String name, String image, String serial, String cost) {
this.name = name;
this.image = image;
this.serial = serial;
this.cost = cost;
}
//getters
}
}
API
@GET("api/v1/components")
Call<ArrayList<Component.Rows>> listComponents();
MainActivity
JsonPlaceHolderApi jsonPlaceHolderApi = ApiClient.getClient().create(JsonPlaceHolderApi.class);
Call<ArrayList<Component.Rows>> call = jsonPlaceHolderApi.listComponents();
call.enqueue(new Callback<ArrayList<Component.Rows>>() {
@Override
public void onResponse(@NonNull Call<ArrayList<Component.Rows>> call, @NonNull Response<ArrayList<Component.Rows>> response) {
ArrayList<Component.Rows> posts = response.body();
componentAdapter = new ComponentAdapter(getApplicationContext(),posts);
listView.setAdapter(componentAdapter);
}
JSON:
{
"total": 1,
"rows": [
{
"id": 1,
"name": "HP ENVY x360 - 13-ag0017nn - 4UE32EA AMD® Raven Ridge Ryzen 7 2700U do 3.8GHz, 13.3", 512GB SSD, 8GB",
"image": "http://server/uploads/components/7cDXBttwk2O5p5sEM5T9raBvW.png",
"serial": "193015227095",
"location": {
"id": 1,
"name": "ICB"
},
Это ответ JSON.