decodeDouble method

double decodeDouble(
  1. String jsonPath,
  2. Object json
)
inherited

Decode a JSON object that is expected to be a double. A string representation of a double is also accepted.

Implementation

double decodeDouble(String jsonPath, Object json) {
  if (json is double) {
    return json;
  } else if (json is int) {
    return json.toDouble();
  } else if (json is String) {
    var value = double.tryParse(json);
    if (value == null) {
      throw mismatch(jsonPath, 'double', json);
    }
    return value;
  }
  throw mismatch(jsonPath, 'double', json);
}