qq_30562993
qq_30562993
采纳率53.8%
2016-03-02 05:47 阅读 4.4k

json解析,获取token的值。 给个代码吧

3

{
"info": {
"authc": { "principal": { "token": "3e5078cb-2f32-4ec4-ad9d-b64fbd966e6e" },
"credentials": null },
"authz": { "roles": [ "SUPERADMIN" ],
"permissions": [
"policeStation:*",
"policeman:*",
"role:*",
"bicycle:*",
"bicycleOwner:*",
"bicycleRegister:*",
"bicycleStolen:*",
"bicycleLastTrack:*",
"InstallBicycle:*",
"InstallRfid:*"
]
}
}
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    luochoudan 丑旦 2016-03-02 06:07

    试试看

        try {
            JSONObject jsonObject = new JSONObject(str);
            JSONObject jsonObject1 = jsonObject.getJSONObject("info");
                        JSONObject jsonObject2 = jsonObject1.getJSONObject("authc");
            JSONObject jsonObject3 = jsonObject2.getJSONObject("principal");
            String token = jsonObject3.getString("token");
            Log.e("token: ", token);
        } catch (JSONException e) {
    
        }
    
    点赞 3 评论 复制链接分享
  • qq_20039385 qq_20039385 2016-03-02 06:27

    首先你给的json格式就错的,转成json会报错。我这里有个json存窜,获取方法如下:
    String str = "{\"base\": {\"token\": \"f374bf142237f29ed2506e60538a435e619edc8ff90ab4b8c46a78bab646fbc5267844f6b633a9f82a9db938c3fcbd8e205ba004b9495e6965e32f5c4bb0c843ab5333d4aa01ed26f75aebb61599a52d\"},\"body\": {}}";
    JSONObject jsonObj = JSONObject.parseObject(str);
    JSONObject basejson = (JSONObject) jsonObj.get("base");
    String token = basejson.getString("token");

    点赞 1 评论 复制链接分享

相关推荐