Source Code:
(back to article)
import org.json.JSONObject; // Parse the JSON string String jsonString = "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}"; JSONObject obj = new JSONObject(jsonString); // Get the value for the key "name" String name = obj.getString("name"); // Get the value for the key "age" int age = obj.getInt("age"); // Get the value for the key "city" String city = obj.getString("city"); System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("City: " + city);
Result:
Report an issue