Json.fromDynamic constructor
Json.fromDynamic(
- dynamic _rawValue, {
- bool initial = true,
Create a Json instance from any value
Implementation
Json.fromDynamic(this._rawValue, {bool initial = true}) {
if (!initial) {
// Type checking has already been done
return;
}
if (_rawValue is Map) {
Map<String, dynamic> map = _rawValue as Map<String, dynamic>;
_rawValue = <String, dynamic>{};
try {
map.forEach((String key, dynamic value) => _set(key, value));
} on JsonException catch (error) {
exception = exception ?? error;
}
} else if (_rawValue is List) {
List<dynamic> list = _rawValue as List<dynamic>;
_rawValue = <dynamic>[];
try {
int i = 0;
for (var item in list) {
_set(i++, item);
}
} on JsonException catch (error) {
exception = exception ?? error;
}
} else if (_rawValue is! int &&
_rawValue is! double &&
_rawValue is! String &&
_rawValue != null &&
_rawValue is! bool) {
exception = exception ?? JsonException(JsonError.unsupportedType);
_rawValue = null;
}
}