java-将列表格式化成json字符串

       List<String> list = new ArrayList<>();
            list.add("{'county':'china','age':18}");
            list.add("{'county':'japan','age':28}");
            String data = JSON.toJSONString(list,SerializerFeature.WriteNullListAsEmpty);
            System.out.println(data);

结果:

"[\"{'county':'china','age':18}\",\"{'county':'japan','age':28}\"]"

 

posted @ 2023-08-23 15:10  陈橙橙橙子  阅读(144)  评论(0编辑  收藏  举报