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, String.class, 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); } } }
相关推荐
somebodyoneday 2020-06-15
adonislu 2020-06-02
baijinswpu 2020-02-19
adonislu 2020-02-14
83163452 2020-01-28
adonislu 2020-01-10
baijinswpu 2020-01-01
adonislu 2019-12-31
baijinswpu 2019-12-28
xufankang 2019-12-19
somebodyoneday 2019-12-07
abcx 2015-05-25
somebodyoneday 2019-10-30
newthon 2019-10-21
ZCMUCZX 2016-04-14
iovaaron 2015-04-10
Dolphinsz 2016-04-25