import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class JSONParserMini { public static void main(String[] args) { String jsonData = "{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}"; try { JSONObject jsonObject = new JSONObject(jsonData); String name = jsonObject.getString("name"); int age = jsonObject.getInt("age"); String city = jsonObject.getString("city"); System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("City: " + city); } catch (JSONException e) { e.printStackTrace(); } } }


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