json解析

{
    "ret":200,
    "data":{
        "code":0,
        "msg":"",
        "info":[
            {
                "gifttoken":"5fd11bf089c78c85bba1c53d30178899",
                "coin":"4290913213",
                "ranknumber":"0",
                "ranknumber_hour":1,
                "lucky_nums":10,
                "lucky_types":"1",
                "gifticon":"https://huanxiu.oss-cn-shanghai.aliyuncs.com/gift/%E5%8D%83%E7%BA%B8%E9%B9%A42%402x.png",
                "giftname":"千纸鹤",
                "giftcount":1,
                "level":"56"
            }
        ]
    },
    "msg":""
}

 

 

 

try {
    JSONObject jsonObject = new JSONObject(response);
    int ret = jsonObject.getInt("ret");
    LogUtils.d("gifttoken:" + ret);
    String data = jsonObject.getString("data");
    LogUtils.d("gifttoken:" + data);
    JSONObject dataObject = new JSONObject(data);
    int code = dataObject.getInt("code");
    LogUtils.d("gifttoken2:" + code);
    JSONArray info = dataObject.getJSONArray("info");
    JSONObject jsonObj = info.getJSONObject(0);
    String giftname = jsonObj.getString("giftname");
    LogUtils.d("gifttoken3:" + giftname);
} catch (JSONException e) {
    e.printStackTrace();
}

你可能感兴趣的:(android)