码迷,mamicode.com
首页 > Web开发 > 详细

Json字符串取值

时间:2019-12-11 09:20:15      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:++   mail   aging   pes   value   字符串   sub   ons   key   

1、案例

  

String str2="{\"roles\":[],\"attributes\":[{\"values\":[\"XXXl001#oa_group\","
                + "\"XXXxl002#stockOA\",\"XXXl003#Wifi_Group\",\"XXXl004#PBC_Group\","
                + "\"XXXl005#MDM_Group\",\"XXXl006#BA_Group\",\"XXXl007#Investment_Group\","
                + "\"XXXl008#Finace_Group\",\"XXXl009#Edoc_Group\",\"XXXl010#GS_Group\","
                + "\"XXX1211@qq.com#coremail_group\",\"XXXl011#BWFP_Group\","
                + "\"XXXl012#1031\",\"XXXl013#ImagingSys_group\","
                + "\"XXXl014@qq.con#coremail_group\",\"XXXl015#BPS_Group\","
                + "\"XXXl016#SAP_Group\",\"XXXl017#MDM_SGDC\",\"XXXl018#SGBA_Group\","
                + "\"XXXl019#MYSOFT_SGSJT\",\"XXXl020#HR_Group\",\"XXXl021#ZC_Group\","
                + "\"XXXl022#ECM_Group\",\"XXXl023#CI_Group\"],\"name\":\"spRoleList\"}],"
                + "\"token\":{\"tokenId\":\"EOJSEFIOJASEJFJSAEFxjijiajsefjasl"
                        + "kMWSWEFJAjsjajJJKLjLJionGTUYugUhiuMw..HLIhIHoihIHihUIGIFuyfIUFu.\"}}";
    //第二种方式  
        Map mapTypes = JSON.parseObject(str2);
       /* for (Object obj : mapTypes.keySet()){  
            System.out.println("key为:"+obj+"值为:"+mapTypes.get(obj));  
        } */
       // System.out.println("这个是用JSON类的parseObject来解析JSON字符串!!!");  
        for (Object obj : mapTypes.keySet()){
            
           if(!"".equals(mapTypes.get("attributes"))) {
               List object = (List) mapTypes.get("attributes");
             /*  String str3 = JSON.toJSONString(object);
             List<Map<String, String>> list = jsonToList(str3);  
               if(list!=null){
                  for (int i = 0; i < list.size(); i++) {
                    Map<String, String> map = list.get(i);
                      for (Object objs : map.keySet()){  
                         //   System.out.println("key为:"+obj+"值为:"+map.get(objs));  
                        }    
                }
               }
               */
               for (int i = 0; i < object.size(); i++) {
                   String str3 = JSON.toJSONString(object.get(i));
                  // System.out.print("++"+str3);
                    JSONObject jsonObject = JSONObject.parseObject(str3);
                //    System.out.println(jsonObject.getString("values"));
                    String str4 = jsonObject.getString("values");
                    String str5 = str4.substring(2,str4.length()-2);
                    String str6 = str5.replaceAll("\",\"", "");
                    System.out.print(str6);
            }
           }
           
        } 

 

Json字符串取值

标签:++   mail   aging   pes   value   字符串   sub   ons   key   

原文地址:https://www.cnblogs.com/sjzxs/p/12020316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!