JSONArray 循环遍历

前端之家收集整理的这篇文章主要介绍了JSONArray 循环遍历前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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);
                }
            } 
        }

猜你在找的Json相关文章