1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| String jsonString = JSON.toJSONString(map);
Map maps = (Map)JSON.parse(str); System.out.println("这个是用JSON类来解析JSON字符串!!!"); for (Object map : maps.entrySet()){ System.out.println(((Map.Entry)map).getKey()+"-" + ((Map.Entry)map).getValue()); } Map mapTypes = JSON.parseObject(str); System.out.println("这个是用JSON类的parseObject来解析JSON字符串!!!"); for (Object obj : mapTypes.keySet()){ System.out.println("key为:"+obj+"值为:"+mapTypes.get(obj)); } Map mapType = JSON.parseObject(str,Map.class); System.out.println("这个是用JSON类,指定解析类型,来解析JSON字符串!!!"); for (Object obj : mapType.keySet()){ System.out.println("key为:"+obj+"值为:"+mapType.get(obj)); } Map<String, Object> map = JSON.parseObject(result, new TypeReference<Map<String, Object>>(){}); JSONArray listObjectSeven = JSON.parseArray(strArr); System.out.println("利用JSON中的parseArray方法来解析json数组字符串"); for(Object mapList : listObjectSeven){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " + ((Map.Entry)entry).getValue()); } }
Map json = (Map) JSONObject.parse(str); System.out.println("这个是用JSONObject类的parse方法来解析JSON字符串!!!"); for (Object map : json.entrySet()){ System.out.println(((Map.Entry)map).getKey()+" "+((Map.Entry)map).getValue()); }
JSONObject jsonObject = JSONObject.parseObject(str); System.out.println("这个是用JSONObject的parseObject方法来解析JSON字符串!!!"); for (Object map : json.entrySet()){ System.out.println(((Map.Entry)map).getKey()+" "+((Map.Entry)map).getValue()); }
Map mapObj = JSONObject.parseObject(str,Map.class); System.out.println("这个是用JSONObject的parseObject方法并执行返回类型来解析JSON字符串!!!"); for (Object map: json.entrySet()){ System.out.println(((Map.Entry)map).getKey()+" "+((Map.Entry)map).getValue()); } JSONArray listObjectFifth = JSONObject.parseArray(strArr); System.out.println("利用JSONObject中的parseArray方法来解析json数组字符串"); for(Object mapList : listObjectFifth){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " + ((Map.Entry)entry).getValue()); } } List listObjectSix = JSONObject.parseArray(strArr,Map.class); System.out.println("利用JSONObject中的parseArray方法并指定返回类型来解析json数组字符串"); for(Object mapList : listObjectSix){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " + ((Map.Entry)entry).getValue()); } }
List<Map<String,String>> listObjectFir = (List<Map<String,String>>) JSONArray.parse(strArr); System.out.println("利用JSONArray中的parse方法来解析json数组字符串"); for(Map<String,String> mapList : listObjectFir){ for (Map.Entry entry : mapList.entrySet()){ System.out.println( entry.getKey() + " " +entry.getValue()); } }
List<Map<String,String>> listObjectSec = JSONArray.parseObject(strArr,List.class); System.out.println("利用JSONArray中的parseObject方法并指定返回类型来解析json数组字符串"); for(Map<String,String> mapList : listObjectSec){ for (Map.Entry entry : mapList.entrySet()){ System.out.println( entry.getKey() + " " +entry.getValue()); } } JSONArray listObjectThir = JSONArray.parseArray(strArr); System.out.println("利用JSONArray中的parseArray方法来解析json数组字符串"); for(Object mapList : listObjectThir){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey()+ ""+ ((Map.Entry)entry).getValue()); } } List listObjectFour = JSONArray.parseArray(strArr,Map.class); System.out.println("利用JSONArray中的parseArray方法并指定返回类型来解析json数组字符串"); for(Object mapList : listObjectFour){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " + ((Map.Entry)entry).getValue()); } }
|