Ошибка при извлечении данных из API с использованием модернизации Это мои данные в формате json Я не понимаю, как получить данные вложенного массива / объекта с помощью модернизации
[
{
"state": "Kerala",
"districtData": [
{
"district": "Thrissur",
"confirmed": 12,
"lastupdatedtime": "",
"delta": {
"confirmed": 0
}
},
{
"district": "Alappuzha",
"confirmed": 3,
"lastupdatedtime": "",
"delta": {
"confirmed": 0
}
},
{
"district": "Kasaragod",
"confirmed": 156,
"lastupdatedtime": "",
"delta": {
"confirmed": 0
}
},
]
}
]
My Resopnse Class:--
public class StateDistrictResponse
{
private String state;
private DistrictDataModal[] districtData;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public DistrictDataModal[] getDistrictData() {
return districtData;
}
public void setDistrictData(DistrictDataModal[] districtData) {
this.districtData = districtData;
}
public StateDistrictResponse(String state, DistrictDataModal[] districtData) {
this.state = state;
this.districtData = districtData;
}
}
POJO CLASS / MODal CLass of DistrictDataModal :: -
public class DistrictDataModal
{
private String district;
private String confirmed;
private String lastupdatedtime;
private DeltaModal delta;
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getConfirmed() {
return confirmed;
}
public void setConfirmed(String confirmed) {
this.confirmed = confirmed;
}
public String getLastupdatedtime() {
return lastupdatedtime;
}
public void setLastupdatedtime(String lastupdatedtime) {
this.lastupdatedtime = lastupdatedtime;
}
public DeltaModal getDelta() {
return delta;
}
public void setDelta(DeltaModal delta) {
this.delta = delta;
}
public DistrictDataModal(String district, String confirmed, String lastupdatedtime, DeltaModal delta) {
this.district = district;
this.confirmed = confirmed;
this.lastupdatedtime = lastupdatedtime;
this.delta = delta;
}
}
и вот мой класс объекта Delta
public class DeltaModal
{
private String confirmed;
public String getConfirmed() {
return confirmed;
}
public void setConfirmed(String confirmed) {
this.confirmed = confirmed;
}
public DeltaModal(String confirmed) {
this.confirmed = confirmed;
}
}
и вот код модификации, и я не понял, как получить данные объекта: -
private void getStateDistrict()
{
Retrofit retrofit= new Retrofit.Builder()
.baseUrl(Apis.ROOT)
.addConverterFactory(GsonConverterFactory.create())
.build();
Apis request=retrofit.create(Apis.class);
Call<StateDistrictResponse> call=request.getState_Distric_Wise();
call.enqueue(new Callback<StateDistrictResponse>() {
@Override
public void onResponse(Call<StateDistrictResponse> call, Response<StateDistrictResponse> response) {
if (response.isSuccessful())
{
try {
StateDistrictResponse response1=response.body();
Toast.makeText(StateDistrict.this, ""+response1.getDistrictData()[i].getDelta().getConfirmed(), Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(StateDistrict.this, "Ex:--"+e.toString(), Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(StateDistrict.this, "SOrry", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<StateDistrictResponse> call, Throwable t) {
Toast.makeText(StateDistrict.this, "SOrry"+t.toString(), Toast.LENGTH_SHORT).show();
}
});
}