Ответ API, имеющего вызов Get, но как получить эти значения из вызова модифицированного Api, в котором вызов выполняется в функции OnFailure и не может получить ответ в фрагменте кода, заданном после функции Response Viz getresponse (). Эта функция создает исключение и не возвращает значения Global, Country и основного класса модели **
The response of the API showing the object with key and having the values, how should one use Values of the key as it is not achievable by my java code snippet
{
"Global": {
"New": 118196,
"Total": 5898252,
"NewD": 4785,
"TotalD": 367273,
"NewR": 65964,
"TotalR": 2415401
},
"Countries": [
{
"Country": "Afghanistan",
"CountryCode": "AF",
"Slug": "afghanistan",
"Date": "2020-05-29T08:39:18Z"
},
{
"Country": "Belarus",
"CountryCode": "BY",
"Slug": "belarus",
"Date": "2020-05-29T08:39:18Z"
},
{
"Country": "Brazil",
"CountryCode": "BR",
"Slug": "brazil",
"Date": "2020-05-29T08:39:18Z"
}
],
"Date": "2020-05-29T08:39:18Z"
}
After making 3 models for this response namely Main, Global, Countries, how to get response values from Global i.e-("New": 118196, "Total": 5898252, "NewD": 4785,"TotalD": 367273,"NewR": 65964,"TotalR": 2415401), Countries({"Country": "Afghanistan", "CountryCode": "AF", "Slug":"afghanistan","Date": "2020-05-29T08:39:18Z"
}), and Main class(Countries,GLobal and Date).
Here is the java function which is-
private void getresponse() {
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(endpointApi.BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
endpointApi api = retrofit.create(endpointApi.class);
Call<List<Main>> call = api.getResult();
call.enqueue(new Callback<List<Main>>() {
@Override
public void onResponse(Call<List<Main>> call, Response<List<Main>> response) {
List<Main> heroList = response.body();
for (int i = 0; i < heroList.size(); i++) {
Integer heroes = heroList.get(i).getCountries().size();
Log.i("test111","test111--"+heroes);
}
}
@Override
public void onFailure(Call<List<Example>> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
t.printStackTrace();
}
});
}
Приведенный выше код java предназначен для модификации для получения ответа от API, как чтобы получить TotalD из объекта Global и Slung from Country в этом фрагменте кода. Приведенный выше код не показывает ответа и переходит к функции onFailure () и не может получить ответ от API как
Here is the Interface code snippet-
public interface endpointApi{
String BASE_URL = "https://api.something.com/";
@GET("summary")
Call<List<Main>> getResult();
}
**How to achieve all values in Global i.e, Countries, and Main model class values?**