【问题标题】:hey i want to show the data in to a nested Recycler-view from my api json response ,only want to list json array-list from the response,嘿,我想从我的 api json 响应中将数据显示到嵌套的 Recycler-view 中,只想从响应中列出 json 数组列表,
【发布时间】:2023-01-25 18:26:00
【问题描述】:


{ “错误”:假​​的, “消息”:“成功”, “数据”: { “项目”: [ { “id”:“i01”, “名称”:“特色” }, { “id”:“i07”, "name": "继续观看" }, { "id": "i03", "name": "推荐" }, { "id": "i04", “名称”:“预告片” }, { “id”:“i05”, “名称”:“最新系列” }, { “id”:“i06”, “名称”:“所有系列” }, { “id”:“i08”, “名称”:“马拉雅拉姆语” }, { “id”:“i09”, “名称”:“泰米尔语” }, { "id": "i10", “名称”:“印地语” }, { “id”:“i11”, “名称”:“泰卢固语” }, { “id”:“i12”, “名称”:“卡纳达语” } ], “精选”:{ “编号”:15, "name": "巫师:世外桃源传说", "description": "Wizards: Tales of Arcadia 动画系列", “海报”:“系列/15/海报/1674561938132-wtoa.jpg”, “活跃”:真实, “创建时间”:“2023-01-18T09:24:27.732Z”, “更新时间”:“2023-01-18T09:24:27.732Z”, “特色”:真实, “导演”: ””, “演员表”:[ { “名称”:“演员1” }, { “名称”:“cast2” } ], “流派”:[ { “编号”:1, “名称”:“行动” }, { “编号”:13, “名称”:“幻想” } ], “季节”:[ { “编号”:10, “series_id”:15, "name": "第一季", "description": "巫师第 1 季:世外桃源传说", “剧集”:[ { “编号”:20, “fwp_id”:“d29433a2-1724-4a6c-a1ba-a6973920b2f3”, “series_id”:15, “season_id”:10, “名称”:“WTOA S1 E1”, "description": "Wizards: Tales of Arcadia Season 1 Episode 2", “海报”:“视频/d29433a2-1724-4a6c-a1ba-a6973920b2f3/海报/1674563591831-wtoa.jpg” }, { “编号”:20, “fwp_id”:“d29433a2-1724-4a6c-a1ba-a6973920b2f3”, “series_id”:15, “season_id”:10, “名称”:“WTOA S1 E1”, "description": "Wizards: Tales of Arcadia Season 1 Episode 2", “海报”:“视频/d29433a2-1724-4a6c-a1ba-a6973920b2f3/海报/1674563591831-wtoa.jpg” }, { “编号”:21, “fwp_id”:“43eb2eab-bb2d-43f0-aa2d-3d4ab18489c0”, “series_id”:15, “season_id”:10, “名称”:“WTOA S1 E2”, "description": "Wizards: Tales of Arcadia Season 1 Episode 2", “海报”:“视频/43eb2eab-bb2d-43f0-aa2d-3d4ab18489c0/海报/1674563538467-wtoa.jpg” }, { “编号”:21, “fwp_id”:“43eb2eab-bb2d-43f0-aa2d-3d4ab18489c0”, “series_id”:15, “season_id”:10, “名称”:“WTOA S1 E2”, "description": "Wizards: Tales of Arcadia Season 1 Episode 2", “海报”:“视频/43eb2eab-bb2d-43f0-aa2d-3d4ab18489c0/海报/1674563538467-wtoa.jpg” } ] } ], “itemId”:“i01” }, “继续观看”:[ { "itemId": "i07", “编号”:15, "name": "巫师:世外桃源传说", "description": "Wizards: Tales of Arcadia 动画系列", “海报”:“系列/15/海报/1674561938132-wtoa.jpg”, “活跃”:真实, “创建时间”:“2023-01-18T09:24:27.732Z”, “更新时间”:“2023-01-18T09:24:27.732Z”, “season_count”:1, “episode_count”:2, “流派”:[ { “编号”:1, “名称”:“行动” }, { “编号”:13, “名称”:“幻想” } ] } ], “推荐的”: [

        {
            "itemId": "i03",
            "id": 10,
            "name": "Castlevania",
            "description": "Castlevania Animated Series",
            "poster": "series/10/poster/1674562131889-castlevania.jpg",
            "active": true,
            "created_at": "2023-01-18T08:51:18.723Z",
            "updated_at": "2023-01-18T08:51:18.723Z",
            "season_count": 2,
            "episode_count": 6,
            "genres": [
                {
                    "id": 13,
                    "name": "Fantasy"
                },
                {
                    "id": 1,
                    "name": "Action"
                }
            ]
        }
    ],
    "trailers": [
        {
            "itemId": "i04",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    ],
    "allSeries": [
        {
            "itemId": "i06",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    ],
    "malayalam": [
        {
            "itemId": "i08",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    "tamil": [
        {
            "itemId": "i09",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    ],
    "hindi": [
        {
            "itemId": "i10",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    ],
    "telugu": [
        {
            "itemId": "i11",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    ],
    "kannada": [
        {
            "itemId": "i12",
            "id": 15,
            "name": "Wizards:Tales of Arcadia",
            "description": "Wizards:Tales of Arcadia Animated Series",
            "poster": "series/15/poster/1674561938132-wtoa.jpg",
            "active": true,
            "created_at": "2023-01-18T09:24:27.732Z",
            "updated_at": "2023-01-18T09:24:27.732Z",
            "season_count": 1,
            "episode_count": 2,
            "genres": [
                {
                    "id": 1,
                    "name": "Action"
                },
                {
                    "id": 13,
                    "name": "Fantasy"
                }
            ]
        }
    ]
},
"details": []

}


我正在尝试使用 Android kotlin 在嵌套的 RecyclerView 中显示来自 JSON 对象的多个数组列表。我已经能够成功解析 JSON 对象并提取数组列表,但我无法在嵌套的 RecyclerView 中显示它们。

这是我正在使用的 JSON 对象的示例

【问题讨论】:

    标签: android json kotlin nestedrecyclerview


    【解决方案1】:

    例如我的简单JSON 多个 Arraylist

    {
    "page":1,
    "per_page":3,
    "total":12,
    "total_pages":4,
    "data": [
        {
            "id": 1,
            "name": "akila",
            "year": 2000,
            "pantone_value": "15-4020"
        },
        {
            "id": 2,
            "name": "prasanth",
            "year": 2001,
            "pantone_value": "17-2031"
        },
        {
            "id": 3,
            "name": "santhiya",
            "year": 2002,
            "pantone_value": "19-1664"
        }
    ]
    

    }

    你必须声明多个数组列表在你的模型类

    例如 MultipleResource 模型类 - JAVA

    public class MultipleResource {
    
    @SerializedName("page")
    public Integer page;
    @SerializedName("per_page")
    public Integer perPage;
    @SerializedName("total")
    public Integer total;
    @SerializedName("total_pages")
    public Integer totalPages;
    @SerializedName("data")
    public List<Datum> data = null;
    
    public class Datum {
    
        @SerializedName("id")
        public Integer id;
        @SerializedName("name")
        public String name;
        @SerializedName("year")
        public Integer year;
        @SerializedName("pantone_value")
        public String pantoneValue;
    
    }
    }
    

    处理多个 json arraylist - 示例代码 (JAVA)

       Call<MultipleResource> call = apiInterface.doGetListResources();
        call.enqueue(new Callback<MultipleResource>() {
            @Override
            public void onResponse(Call<MultipleResource> call, Response<MultipleResource> response) {
                Log.d("TAG", response.code()+"");
                String displayResponse = "";
    
                MultipleResource resource = response.body();
                Integer text = resource.page;
                Integer total = resource.total;
                Integer totalPages = resource.totalPages;
                List<MultipleResource.Datum> datumList = resource.data;
    
                displayResponse += "Page :" + text + "
    " + "Total :" + total + "
    " + "Total Pages :" + totalPages;
    
                for (MultipleResource.Datum datum : datumList){
                    displayResponse += "
    " + datum.id + "" + datum.name + datum.pantoneValue + datum.year ;
                }
                responseText.setText(displayResponse);
            }
    
            @Override
            public void onFailure(Call<MultipleResource> call, Throwable t) {
    
            }
        });
    

    output

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2019-12-24
      • 2019-12-02
      • 1970-01-01
      • 2020-07-02
      • 2018-03-22
      • 1970-01-01
      相关资源
      最近更新 更多