fromMap function

JSONObject fromMap(
  1. Map<Object?, Object?> map
)

Implementation

JSONObject fromMap(Map<Object?, Object?> map) {
  return JSONObject(map.map((rawKey, value) {
    String key = rawKey as String;
    if (value is Map<Object?, Object?>) {
      return MapEntry(key, fromMap(value));
    } else if (value is List<Object?>) {
      return MapEntry(key, _fromList(value));
    } else if (value is String) {
      return MapEntry(key, JSONString(value));
    } else if (value is double) {
      return MapEntry(key, JSONNumber(value));
    } else if (value is bool) {
      return MapEntry(key, JSONBool(value));
    } else if (value == null) {
      return MapEntry(key, JSONNull());
    } else {
      throw Exception("Unexpected type ${value.runtimeType} in JSON map");
    }
  }));
}