JSONBuilder可以向文件中写入写入json字符串。如下面的例子:
1 public class Test 2 { 3 public static void main(String args[]) throws IOException 4 { 5 File f = new File("d:" + File.separator + "test.txt"); 6 FileWriter fw = new FileWriter(f); 7 JSONBuilder builder = new JSONBuilder(fw); 8 builder.object(); 9 builder.key("Json"); 10 builder.value("Hello, World!"); 11 builder.endObject(); 12 fw.flush(); 13 fw.close(); 14 } 15 }
时间: 2024-10-08 10:44:26