Json数据示例:

{"product":{"result":"1","data":{"value":"4"},"costTime":15,"operation":"3"},"code":600000,"flag":{"flag_telperiod":1},"swift_number":"3100034_20161221153228_0705","exceptions":[]}

目的,要获取value:

方案:

        //第一种方式
        /*JSONObject json = JSONObject.fromObject(obj);
        String product = json.optString("product");
        json = JSONObject.fromObject(product);
        product = json.optString("data");
        json = JSONObject.fromObject(product);
        product = json.optString("value");
        int value = Integer.parseInt(product.toString());*/

        //第二种方式
        JSONObject jsonObject = new JSONObject().fromObject(obj.toString());
        Object data=jsonObject.get("product");
        jsonObject = new JSONObject().fromObject(data.toString());
        data=jsonObject.get("data");
        jsonObject = new JSONObject().fromObject(data.toString());
        data=jsonObject.get("value");
        int value = Integer.parseInt(data.toString());
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 2 个月前
8c391e04 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐