遍历json

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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值