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();
}
}
}
04-18
4316
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-23
5475
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交