import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONArray; String jsonStr = "{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}"; try { JSONObject jsonObj = new JSONObject(jsonStr); String name = jsonObj.getString("name"); int age = jsonObj.getInt("age"); String city = jsonObj.getString("city"); System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("City: " + city); } catch (Exception e) { e.printStackTrace(); } import org.codehaus.jettison.json.JSONObject; try { JSONObject jsonObj = new JSONObject(); jsonObj.put("name", "John"); jsonObj.put("age", 30); jsonObj.put("city", "New York"); String jsonStr = jsonObj.toString(); System.out.println(jsonStr); } catch (Exception e) { e.printStackTrace(); }


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