import org.json.*; public class Example { public static void main(String[] args) { String jsonString = "{\"price\": 10.99}"; JSONObject jsonObject = new JSONObject(jsonString); double price = jsonObject.getDouble("price"); System.out.println("Price: " + price); } }
import org.json.*; public class Example { public static void main(String[] args) { String jsonString = "{\"price\": \"10.99\"}"; JSONObject jsonObject = new JSONObject(jsonString); double price = jsonObject.getDouble("price"); System.out.println("Price: " + price); } }
Exception in thread "main" org.json.JSONException: Value 10.99 of type java.lang.String cannot be converted to doubleThis method is part of the org.json package library.