引入org.json包
JSONObject obj = new JSONObject();
obj.put(key, value);
String json = obj.toString();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "scott");
map.put("sex", "male");
map.put("age", 24);
map.put("hobbies", new String[] {"hiking", "swimming"});
JSONObject obj = new JSONObject(map);
String json = obj.toString();
Person person = new Person("scott","male",24,new String[] {"hiking", "swimming"});
JSONObject obj = new JSONObject(person);
String json = obj.toString();
String jsonStr = "...";
JSONObject obj = new JSONObject(content);
String name = obj.getString("name");
String sex = obj.getString("sex");
String age = obj.getString("age");
JSONArray hobbies = obj.getJSONArray("hobbies");
for (int i = 0; i < hobbies.length(); i++) {
String s = (String) hobbies.get(i);
System.out.println(s);
}