import org.miniedition.parser.JSONParser; import org.miniedition.parser.ParseException; import org.miniedition.parser.JSONValue; import org.miniedition.parser.JSONArray; import org.miniedition.parser.JSONObject; public class JSONParserExample { public static void main(String[] args) { String json = "{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}"; try { JSONValue jsonValue = JSONParser.parse(json); if (jsonValue instanceof JSONObject) { JSONObject jsonObject = (JSONObject) jsonValue; String name = (String) jsonObject.get("name"); int age = (int) jsonObject.get("age"); String city = (String) jsonObject.get("city"); System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("City: " + city); } } catch (ParseException e) { e.printStackTrace(); } } }


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