如何在Android中处理嵌套的json对象 [英] How to deal with nested json OBJECTS in android

查看:247
本文介绍了如何在Android中处理嵌套的json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在android中读取json以下内容?请使用JSONObject jsonObject;

How to read below json in android? Please provide solution using JSONObject jsonObject;

我想要这个

{
    "resourceName": "bags_wallets_belts",
    "get": "https://affiliate-api.flipkart.net/affiliate/feeds/youraffiliateid/category/v1:reh.json?expiresAt=1420910131274&sig=7db02590dfaea9a22f88c869d8035d05",
    "post": null,
    "put": null,
    "delete": null
}

通过使用以下json:.

{
"title": "Flipkart Affiliate API Directory",
"description": "This directory contains information about all the affiliate API's and their versions",
"apiGroups": {
    "affiliate": {
        "name": "affiliate",
        "apiListings": {
            "bags_wallets_belts": {
                "availableVariants": {
                    "v0.1.0": {
                        "resourceName": "bags_wallets_belts",
                        "get": "https://affiliate-api.flipkart.net/affiliate/feeds/youraffiliateid/category/v1:reh.json?expiresAt=1420910131274&sig=7db02590dfaea9a22f88c869d8035d05",
                        "post": null,
                        "put": null,
                        "delete": null
                    }
                },
                "apiName": "bags_wallets_belts"
            },
            "washing_machine": {
                "availableVariants": {
                    "v0.1.0": {
                        "resourceName": "washing_machine",
                        "get": "https://affiliate-api.flipkart.net/affiliate/feeds/youraffiliateid/category/v1:j9e-abm-8qx.json?expiresAt=1420910131275&sig=7c48abab9d35ae77fff3d998e1a2efdc",
                        "post": null,
                        "put": null,
                        "delete": null
                    }
                },
                "apiName": "washing_machine"
            },
            "mens_footwear": {
                "availableVariants": {
                    "v0.1.0": {
                        "resourceName": "mens_footwear",
                        "get": "https://affiliate-api.flipkart.net/affiliate/feeds/youraffiliateid/category/v1:osp-cil.json?expiresAt=1420910131274&sig=f7ac9d1c19ae39b226c0ca46725d609d",
                        "post": null,
                        "put": null,
                        "delete": null
                    }
                },
                "apiName": "mens_footwear"
            }
        }
    }
}

}

谢谢.

推荐答案

您也可以尝试一下.

下面将为您解析一个节点,其余的您都可以完成.

The below will parse a single node for you and you can do the rest.

JSONObject jMainObject = null;
    try {
        jMainObject = new JSONObject(jsonString);
        JSONObject apiGroupsObject = jMainObject.getJSONObject("apiGroups");
        JSONObject affiliateObject = apiGroupsObject.getJSONObject("affiliate"); 
        JSONObject apiListingsObject = affiliateObject.getJSONObject("apiListings");
        JSONObject bags_wallets_beltsObject = apiListingsObject.getJSONObject("bags_wallets_belts");
        JSONObject availableVariantsObject = bags_wallets_beltsObject.getJSONObject("availableVariants");
        JSONObject versionObject = availableVariantsObject.getJSONObject("v0.1.0");
        System.out.println(versionObject);
    } catch (JSONException e) {
        e.printStackTrace();
    }

这篇关于如何在Android中处理嵌套的json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆