JSON内容如下
{
“resultCode” : “success”,
“resultMsg” : “缓存查询成功!”,
“cacheList” : [ {
“region” : “WebAppCacheRegion”,
“key” : “com.tianan.translate.data.service.impl.TianAnEnumSerivceImpl.getEnumName.insureService.passWord”,
“level” : “1”,
“size” : “432 bytes”
}, {
“region” : “WebAppCacheRegion”,
“key” : “com.tianan.translate.data.service.impl.TianAnEnumSerivceImpl.getEnumName.insureService.userName”,
“level” : “1”,
“size” : “416 bytes”
}, {
“region” : “WebAppCacheRegion”,
“key” : “com.tianan.translate.data.service.impl.TianAnEnumSerivceImpl.getEnumName.insureService.targetId”,
“level” : “1”,
“size” : “416 bytes”
} ]
}
获取以上JSON中的cacheList
@RequestMapping(value = "/doGetCpfCacheJson.mvc")
public @ResponseBody JSONObject doGetCpfCacheJson(HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
JSONObject jsonObj = new JSONObject();
List<Enum> ipList = tianAnEnumService.findByDictcode(Constants.CACHE_IP);
try {
JSONArray jsonList = new JSONArray();
for (int i = 0; i < ipList.size(); i++) {
JSONObject jsonObj2 = new JSONObject();
String cacheStr = HttpUtils.postJsonBody("http://" + ipList.get(i).getCode() + ":8001/tianan_cpf/common/cache/cacheSelect.mvc", "");
jsonObj2 = JSONObject.fromObject(cacheStr);
JSONArray jsonList2 = JSONArray.fromObject(jsonObj2.get("cacheList"));
if (jsonList2 != null) {
for (int j = 0; j < jsonList2.size(); j++) {
JSONObject subObj = (JSONObject) jsonList2.get(j);
subObj.put("region", subObj.get("region"));
subObj.put("key", subObj.get("key"));
subObj.put("level", subObj.get("level"));
subObj.put("size", subObj.get("size"));
jsonList.add(subObj);
}
}
}
jsonObj.put("rows", jsonList);
jsonObj.put("total", jsonList.size());
logger.debug("缓存JSON数据:"+jsonObj.toString());
} catch (Exception e) {
logger.error("缓存请求过程中异常:"+e.getMessage(),e);
}
return jsonObj;
}