当解析 JSONArray 在 Retrofit 列表中排在最后时?

When parsing JSONArray comes last in the list of Retrofit?

我通过 GET

得到了 json 请求
{"data": [
    "Черногория",
    "Чехия",
    "Чили"
]}

如果需要在单独的项目中显示每个国家/地区,如何解析它。我正在使用 Pojo。

@SerializedName("data")
    @Expose
    private ArrayList<String> data = null;

这是一个activity,我在其中使用改造连接,一切都来了,但只显示列表中的最后一个字段

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));
            }

我认为您是一次性添加所有数据,而不是一个接一个地添加 arrayList.add(countries);你应该做 arrayList.add(countries.getData().get(x)); 然后在循环外你应该写 viewAdapterCountry.notifyDataSetChanged();

在适配器的 bindivewholder 中

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val item = list?.get(position)

        holder.button.setText(item)

    }