/** * Returns the value mapped by {@code name} if it exists and is a double or can be coerced to a * double. * * @throws JSONException if the mapping doesn't exist or cannot be coerced to a double. */ public double getDouble(String name) throws JSONException { Object object = get(name); Double result = JSON.toDouble(object); if (result == null) { throw JSON.typeMismatch(name, object, "double"); } return result; }
/** * Returns the value mapped by {@code name} if it exists and is a double or can be coerced to a * double. Returns {@code fallback} otherwise. */ public double optDouble(String name, double fallback) { Object object = opt(name); Double result = JSON.toDouble(object); return result != null ? result : fallback; }