Java 数据输出JSON文件

public static void main(String[] args) {
    try {
        List<Object> list = Lists.newArrayList();
        Map<String, String> map = new HashMap<>();
        map.put("name", "张三");
        list.add(map);
        ObjectMapper objectMapper = new ObjectMapper();
        File newFile = new File("C:/Users/Administrator/Desktop/test.json");
        objectMapper.writeValue(newFile, list);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
posted @ 2024-07-12 10:48  Liberty&  阅读(36)  评论(0)    收藏  举报