fromJson<T> static method

T fromJson<T>(
  1. String json
)

Deserializes JSON text into type T.

Implementation

static T fromJson<T>(String json) {
  final dynamic decoded = jsonDecode(json);

  if (decoded is Map<String, dynamic>) {
    return _decodeMap<T>(decoded);
  }

  if (decoded == null || decoded is num || decoded is bool || decoded is String) {
    return decoded as T;
  }

  throw ArgumentError('Unsupported JSON payload for type $T');
}