Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * 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;
 }