JsonConverter class
Converts arbitrary values from and to JSON (JavaScript Object Notation) strings.
Example
var value1 = JsonConverter.fromJson("{\"key\":123}"); // Result: { "key": 123 }
var value2 = JsonConverter.toMap({ "key": 123 }); // Result: "{ "key": 123 }"
See [TypeCode]
Constructors
Properties
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited
Static Methods
-
fromJson<
T> (TypeCode type, String value) → T -
- Converts JSON string into a value of type specified by a TypeCode.
-
type
the TypeCode for the data type into which 'value' is to be converted.
-
- value the JSON string to convert.
- Returns converted object value or null when value is null.
- Converts JSON string into a value of type specified by a TypeCode.
-
toJson(
dynamic value) → String -
- Converts value into JSON string.
-
value
the value to convert.
- Returns JSON string or null when value is null.
- Converts value into JSON string.
-
toMap(
String value) → Map< String, dynamic> -
- Converts JSON string into map object or returns empty map when conversion is not possible.
-
value
the JSON string to convert.
- Returns Map object value or empty object when conversion is not supported.
- See [toNullableMap]
- Converts JSON string into map object or returns empty map when conversion is not possible.
-
toMapWithDefault(
String value, Map< String, dynamic> defaultValue) → Map<String, dynamic> -
- Converts JSON string into map object or returns default value when conversion is not possible.
-
value
the JSON string to convert.
-
- defaultValue the default value. Returns Map object value or default when conversion is not supported.
- See [toNullableMap]
- Converts JSON string into map object or returns default value when conversion is not possible.
-
toNullableMap(
String value) → Map< String, dynamic> -
- Converts JSON string into map object or returns null when conversion is not possible.
-
value
the JSON string to convert.
- Returns Map object value or null when conversion is not supported.
- See [MapConverter.toNullableMap]
- Converts JSON string into map object or returns null when conversion is not possible.