bsp; obj2.put("title","BOOK"); obj2.put("signing", obj7); js.object().key("session").value(obj2).endObject(); System.out.println(js.toString()); PrintWriter out = new PrintWriter(new FileOutputStream(1.txt)); out.println(js.toString()); } } 以上代码生成了如下JSON格式: {"section":{ "title":"BOOK", "signing":[ { "author": { "name":"author-1" }, "book": { "title":"book1", "price":"$11" } }, { "author": { "name":"author-2" }, "book": { "title":"book2", "price":"$22" } } ]} } } 5.JSONTokener代码示例 JSONTokener是用来读取JSON格式的文件;JSONObject obj = new JSONObject( new JSONTokener(java.io.Reader));可以从文件中读取一个JSONObject;JSONArray obj = new JSONArray( new JSONTokener(java.io.Reader)); 可以从文件中读取一个JSONArray;1.txt { 'name':'xiazdong', 'book':['book1','book2'] } package com.xiazdong.json; import java.io.File; import java.io.FileReader; import weibo4j.org.json.JSONObject; import weibo4j.org.json.JSONTokener; publicclass JsonStringerDemo { publicstaticvoid main(String[] args) throws Exception{ JSONObject obj = new JSONObject(new JSONTokener(new FileReader(new Fi