如何在Retrofit中从给定的JSON获取resourceName和get参数?

时间:2017-09-08 10:31:17

标签: android

{
    "title": "Flipkart Affiliate API Directory",
    "description": "This directory contains links for Product Feed API and Delta Feed API of all categories with all the versions available",
    "apiGroups": {
        "affiliate": {
            "name": "affiliate",
            "apiListings": {
                "food_nutrition": {
                    "availableVariants": {
                        "v1.1.0": {
                            "resourceName": "food_nutrition",
                            "put": null,
                            "delete": null,
                            "post": null,
                            "get": "https://affiliate-api.flipkart.net/affiliate/1.0/feeds/keshav/category/7jv.json?expiresAt=1504895695325&sig=b25c6a83d531ef40377203de9ea148d3",
                            "deltaGet": "https://affiliate-api.flipkart.net/affiliate/1.0/deltaFeeds/keshav/category/7jv.json?expiresAt=1504895695326&sig=c2cc339de1f7fabad8113d82428b837e",
                            "top": "https://affiliate-api.flipkart.net/affiliate/1.0/topFeeds/keshav/category/7jv.json?expiresAt=1504895695326&sig=d66f64ee728f1978bc9cfd3a87ca4df3"
                        },
                        "v0.1.0": {
                            "resourceName": "food_nutrition",
                            "put": null,
                            "delete": null,
                            "post": null,
                            "get": "https://affiliate-api.flipkart.net/affiliate/feeds/keshav/category/7jv.json?expiresAt=1504895695326&sig=8dd00a35f90d53e44b544a20b5215898",
                            "deltaGet": "https://affiliate-api.flipkart.net/affiliate/deltaFeeds/keshav/category/7jv.json?expiresAt=1504895695326&sig=8dd00a35f90d53e44b544a20b5215898",
                            "top": null
                        }
                    },
                    "apiName": "food_nutrition"
                },
                "televisions": {
                    "availableVariants": {
                        "v1.1.0": {
                            "resourceName": "televisions",
                            "put": null,
                            "delete": null,
                            "post": null,
                            "get": "https://affiliate-api.flipkart.net/affiliate/1.0/feeds/keshav/category/ckf-czl.json?expiresAt=1504895695324&sig=8ddac7793632a7bba2923c414e89dc1e",
                            "deltaGet": "https://affiliate-api.flipkart.net/affiliate/1.0/deltaFeeds/keshav/category/ckf-czl.json?expiresAt=1504895695324&sig=8ddac7793632a7bba2923c414e89dc1e",
                            "top": "https://affiliate-api.flipkart.net/affiliate/1.0/topFeeds/keshav/category/ckf-czl.json?expiresAt=1504895695324&sig=56301eee9cc9c5d9504432868eeb97f3"
                        },
                        "v0.1.0": {
                            "resourceName": "televisions",
                            "put": null,
                            "delete": null,
                            "post": null,
                            "get": "https://affiliate-api.flipkart.net/affiliate/feeds/keshav/category/ckf-czl.json?expiresAt=1504895695324&sig=cea0487d37d2c906a698b73a7448950a",
                            "deltaGet": "https://affiliate-api.flipkart.net/affiliate/deltaFeeds/keshav/category/ckf-czl.json?expiresAt=1504895695324&sig=cea0487d37d2c906a698b73a7448950a",
                            "top": null
                        }
                    },
                    "apiName": "televisions"
                },




 }
        }
    }
}
String data = response.body().getAffiliate().getApiListings().getFoodNutrition().getAvailableVariants().getV110().getResourceName(); 

我正在尝试获取resourceName的列表并获取每个ApiListings

我有所有Model类,但我不知道如何在一个List中获取所有资源名称并在另一个值中“获取”。

1 个答案:

答案 0 :(得分:0)

试试这个

我使用解析JSON对象和JSON数组完成了这项工作,从this获取帮助,