import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONArray; public class JettisonExample { public static void main(String[] args) throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "John Doe"); jsonObject.put("age", 25); jsonObject.put("isStudent", true); System.out.println(jsonObject.toString()); } } json {"name": "John Doe", "age": 25, "isStudent": true} public class JettisonExample { public static void main(String[] args) throws JSONException { String json = "{\"name\": \"John Doe\", \"age\": 25, \"isStudent\": true}"; JSONObject jsonObject = new JSONObject(json); String name = jsonObject.getString("name"); int age = jsonObject.getInt("age"); boolean isStudent = jsonObject.getBoolean("isStudent"); System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Is Student: " + isStudent); } } Name: John Doe Age: 25 Is Student: true


上一篇:
下一篇:
切换中文