Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么时候解析JSONArray在改造列表中排在最后?_Java_Android_Json_Parsing_Retrofit - Fatal编程技术网

Java 什么时候解析JSONArray在改造列表中排在最后?

Java 什么时候解析JSONArray在改造列表中排在最后?,java,android,json,parsing,retrofit,Java,Android,Json,Parsing,Retrofit,我通过get获得json请求 {"data": [ "Черногория", "Чехия", "Чили" ]} 如果需要在单独的项目中显示每个国家,如何解析它。我用的是Pojo @SerializedName("data") @Expose private ArrayList<String> data = null; @SerializedName(“数据”) @暴露 私有ArrayList数据=null; 这是一个我使用改装连接的

我通过get获得json请求

{"data": [
    "Черногория",
    "Чехия",
    "Чили"
]}
如果需要在单独的项目中显示每个国家,如何解析它。我用的是Pojo

@SerializedName("data")
    @Expose
    private ArrayList<String> data = null;
@SerializedName(“数据”)
@暴露
私有ArrayList数据=null;
这是一个我使用改装连接的活动,一切都来了,但只显示列表中的最后一个字段

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();
                    }}}
        }
public void onResponse(调用、响应){
if(response.code()==200){
Countries=response.body();
如果(国家!=null){

对于(int x=0;x我认为您是一次添加所有数据,而不是逐个添加
arrayList.add(countries);
您应该执行
arrayList.add(countries.getData().get(x));
然后在循环外部编写
viewAdapterCountry.notifyDataSetChanged();

在适配器的活页夹中

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

        holder.button.setText(item)

    }

您不是总是用
viewHolder.button.setText(country.get(x));
覆盖按钮文本吗?所以列表中的最后一个条目就是您看到的条目?执行此操作,viewHolder.button.setText(country.toString());显示所有内容,但不是在每个按钮中,而是在一个按钮中
    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val item = list?.get(position)

        holder.button.setText(item)

    }