При парсинге JSONArray приходит последний в списке Retrofit?
Получаю через GET запрос json
{"data": [
"Черногория",
"Чехия",
"Чили"
]}
Как его распарсить если нужно каждую страну вывести в отдельный item. Использую Pojo.
@SerializedName("data")
@Expose
private ArrayList<String> data = null;
это активити в которой я использую retrofit для подключения, все приходит, но выводит только последнее поле в списки
public void onResponse(Call<Countries> call, Response<Countries> response) {
if (response.code() == 200) {
Countries countries = response.body();
if (countries != null) {
for (int x =0; x<countries.getData().size(); x++) {
arrayList.add(countries);
viewAdapterCountry.notifyDataSetChanged();
}}}
}
а вот адаптер
private ArrayList<Countries> countryModels;
Countries countryModel = countryModels.get(i);
List<String> country = countryModel.getData();
for (int x = 0; x<country.size(); x++){
viewHolder.button.setText(country.get(x));
}
Ответы (1 шт):
Автор решения: Alex_Skvortsov
→ Ссылка
Переделайте так:
public void onResponse(Call<Countries> call, Response<Countries> response) {
if (response.code() == 200) {
Countries countries = response.body();
if (countries != null) {
for (int x =0; x<countries.getData().size(); x++) {
arrayList.add(countries.getData().get(x));
}
viewAdapterCountry.notifyDataSetChanged();
}
}
}