加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JSONArray 循环遍历

发布时间:2020-12-16 19:21:08 所属栏目:百科 来源:网络整理
导读:SetString roleNames = new LinkedHashSetString(); SetString permissions = new LinkedHashSetString(); try { jsonStr = restTemplate.getForObject(url,String.class,urlVariables); if (StringUtils.isBlank(jsonStr)) { jsonStr = AUTH_CENTER_INTERFA
Set<String> roleNames = new LinkedHashSet<String>();
        Set<String> permissions = new LinkedHashSet<String>();
        try {
            jsonStr = restTemplate.getForObject(url,String.class,urlVariables);
            if (StringUtils.isBlank(jsonStr)) {
                jsonStr = AUTH_CENTER_INTERFACE_ERROR;
            }
            JSONObject jsonObject = JSONObject.parSEObject(jsonStr);

            if (null != jsonObject) {
                if (jsonObject.containsKey("errorCode") && jsonObject.getInteger("errorCode") == 0) {
                    if (jsonObject.containsKey("data")) {
                        JSONObject data = jsonObject.getJSONObject("data");
                        if (null != data && data.containsKey("roles")) {
                            JSONArray rolesArray = JSON.parseArray(data.getString("roles"));
                            for (int i = 0; i < rolesArray.size(); i++) {
                                JSONObject role = rolesArray.getJSONObject(i);
                                if (null != role && role.containsKey("name")) {
                                    String name = role.getString("name");
                                    if (StringUtils.isNotBlank(name)) {
                                        roleNames.add(name);
                                    }
                                }
                            }
                        }
                        if (permissionsLookupEnabled) {
                            if (null != data && data.containsKey("permissions")) {
                                JSONArray permissionsArray = JSON.parseArray(data.getString("permissions"));
                                for (int i = 0; i < permissionsArray.size(); i++) {
                                    JSONObject permission = permissionsArray.getJSONObject(i);
                                    if (null != permission && permission.containsKey("identifier")) {
                                        String identifier = permission.getString("identifier");
                                        if (StringUtils.isNotBlank(identifier)) {
                                            permissions.add(identifier);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


List<Picture> ret = new ArrayList<Picture>();
        String jsonStr = restTemplate.getForObject(phpUrl,vars);
        if (StringUtils.isNotBlank(jsonStr)) {
            JSONObject jsonObj = JSON.parSEObject(jsonStr);
            int status = jsonObj.getIntValue("status");
            if (status == PHP_OP_SUCCESS) {
                ret = new ArrayList<Picture>();
                JSONObject dataJson = jsonObj.getJSONObject("content");
                JSONArray jsonList = dataJson.getJSONArray("data");
                for (Object obj : jsonList) {
                    JSONObject jobj = (JSONObject) obj;
                    int picId = jobj.getIntValue("pid");
                    String picUrl = jobj.getString("pUrl");
                    Picture pic = new Picture();
                    pic.setPicId(picId);
                    pic.setPicUrl(picUrl);
                    ret.add(pic);
                }
            } 
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读