import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
String json = "{\"name\":\"John\", \"age\":30}"; // JSON字符串
try (FileWriter file = new FileWriter("output.json")) {
ObjectMapper objectMapper = new ObjectMapper();
// 写入JSON到文件
objectMapper.writeValue(file, json);
System.out.println("成功保存JSON文件!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
java保存string为json文件
最新推荐文章于 2024-07-14 22:18:32 发布