使用
http://www.json.org/java/index.html 上面的 Java 类。
package com.clark.app;
import org.json.JSONArray;
import org.json.JSONObject;
public class QuestionMain {
public static void main(String[] args) {
JSONObject object = new JSONObject();
JSONArray array = new JSONArray();
JSONObject city = new JSONObject();
city.put("city", "北京");
array.put(city);
JSONObject locationObj = new JSONObject();
JSONArray locationArr = new JSONArray();
locationArr.put("海淀");
locationArr.put("昌平");
locationArr.put("朝阳");
locationObj.put("location", locationArr);
array.put(locationObj);
object.put("key", array);
object.put("index", "BJ");
System.out.println(object);
}
}