json map and objects

Code

   @RequestMapping("/gett")
    public Map getCeshii() {
        Map<Integer,Integer> map = new HashMap<>();
        map.put(1, 11);
        String json = JSON.toJSONString(map);
        System.out.println(json + "  json");
        Map<Integer, Integer> mapData = JSON.parseObject(json, new TypeReference<Map<Integer, Integer>>() {
        });
        System.out.println(mapData + "  mapData");
        return mapData;
    }

result
Insert picture description here

    @RequestMapping("/gettt")
    public Map getCeshiii() {
        Map<Integer, Integer> map = new HashMap<>();
        map.put(1, 2);
        map.put(2, 3);
        map.put(3, 4);
        String json = JSON.toJSONString(map);
        System.out.println(json + "  json");

        Map<Integer, Integer> map1 = JSON.parseObject(json, Map.class);
        Map<Integer, Integer> integerMap = JSON.parseObject(json, new TypeReference<Map<Integer, Integer>>() {
        });
        System.out.println(integerMap + "  integerMap");
        System.out.println(map1 + "  map1");
        return integerMap;
    }

Insert picture description here
Persistence or non-persistence in this life is not terrible. What I am afraid of is walking on the road of persistence alone! ! !

Guess you like

Origin blog.csdn.net/taiguolaotu/article/details/112367447