Map类型的Json格式

示例代码:

Map<String, Object> map = new HashMap<>();
// boolean 类型 map.put("boolean", true);
// String 类型 map.put("string", "abc");
// int 类型 map.put("int", 123);
// 数组类型 map.put("array", new int[]{1,2,3});
// map 类型 Map<String, Object> subMap = new HashMap<>(); subMap.put("key1", "value1"); subMap.put("key2", "value2"); map.put("map", subMap); System.out.println(JSON.toJSONString(map, true));

结果:

{
    "boolean":true,
    "string":"abc",
    "array":[1,2,3],
    "map":{
        "key1":"value1",
        "key2":"value2"
    },
    "int":123
}

 

posted @ 2021-06-24 18:33  小路亚  阅读(13025)  评论(0编辑  收藏  举报