json字符串的解析很管用的很多启发

            HttpServletResponse response) {
        HashMap<String, String> httpHeaderMap = new HashMap<String, String>();
        httpHeaderMap.put("Content-type" , "application/json; charset=utf-8");
        String accessToken=(String)request.getSession().getAttribute("AccessToken");
        StringBuffer sb = new StringBuffer(APIURLUtils.getUrl("querycredittop"));
        Map<String, Object[]> parameterMap = request.getParameterMap();
        sb.append("?").append("accessToken=").append(accessToken);
        Iterator<Entry<String, Object[]>> iterator = parameterMap.entrySet().iterator();
        while(iterator.hasNext()){
            Entry<String, Object[]> entry = iterator.next();
            if(!"method".equals(entry.getKey())){
                try {
                    if(entry.getValue()[0].toString()!=""){
                        sb.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue()[0].toString(),"utf-8"));
                    }
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        }
        HttpClient client = new DefaultHttpClient();
        try {
            String rp = HttpClientUtils.getResponseFromGetMethod(client,sb.toString(), "utf-8");
            StringBuffer sb1 = new StringBuffer(APIURLUtils.getUrl("getStbDevice"));
            sb1.append("?").append("accessToken=").append(accessToken);
            sb1.append("&serviceCapability=").append("2").append("&hasLogicValue=").append("0");
            String partnerId = (String) request.getSession().getAttribute(SessionInfo.PARTNERID.toString());
            if(Integer.parseInt(partnerId)!=0){
                 sb1.append("&vspId=").append(partnerId);
             }
            String rpstr = HttpClientUtils.getResponseFromGetMethod(client,sb1.toString(), "utf-8");
            System.out.println(rpstr);
            JSONObject node = JSONObject.fromObject(rp);
            JSONArray jsons = JSONArray.fromObject(node.get("data"));
            JSONObject nodes = JSONObject.fromObject(rpstr);
            JSONArray jsonsobs = JSONArray.fromObject(nodes.get("stbDeviceList"));
            JSONArray sonjsonsobs=new JSONArray();
               for (Object o1 : jsons){
                   JSONObject jsonNode1 = JSONObject.fromObject(o1);
                   String devicecode=jsonNode1.getString("deviceCode");
                for (Object o : jsonsobs)
                 {
                    JSONObject jsonNode = JSONObject.fromObject(o);  
                    if(devicecode.equals(jsonNode.getString("deviceCode"))){
                        sonjsonsobs.add(jsonNode);
                    }
                 }
             }
               jsonsobs.removeAll(sonjsonsobs);
               String finalstr="{"+"stbDeviceList:"+jsonsobs.toString()+"}";
            return finalstr;
         } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值