首页 > 解决方案 > 如何解析json对象内的json数组?

问题描述

我尝试在我的代码中设置这种类型的 json 响应我尝试在一个文本视图中设置问题并为其他文本视图设置答案

{
"subcategory": {
    "id": 1,
    "category_id": 1,
    "name": "MLB - Major League Baseball",
    "upload": null,
    "total_points": [
        {
            "id": 1,
            "user_id": 3,
            "subcategory_id": 1,
            "total": 10
        }
    ],
    "questions": [
        {
            "id": 1,
            "subcategory_id": 1,
            "question": "This is a test question.",
            "link": "",
            "banner_link": "",
            "answers": [
                {
                    "id": 1,
                    "question_id": 1,
                    "answer": "Answer 1",
                    "point": 10
                },
                {
                    "id": 2,
                    "question_id": 1,
                    "answer": "Answer 2",
                    "point": 20
                },
                {
                    "id": 3,
                    "question_id": 1,
                    "answer": "Answer 3",
                    "point": 30
                },
                {
                    "id": 4,
                    "question_id": 1,
                    "answer": "Answer 4",
                    "point": 40
                }
            ],

}

如何在android中传递这种类型的json响应,例如一个文本视图中的问题显示和另一个文本视图中的答案显示?

标签: androidjson

解决方案


首先,您应该向您的应用程序文件添加依赖gradle项,然后您将能够使用@Serializejava 对象类中的注释来序列化您的 json 对象。之后,您可以将您的问题和答案放在适当的位置TextView


推荐阅读