Json class
Support handling of jsonDecode JSON representation.
This class supports handling of object graphs obtained from
jsonDecode (or from any other source using the same encoding). In
this encoding, JSON values are represented as as primitive values
(of type Null, bool, int, double, String) or composite
values (of type List<dynamic> or Map<String, dynamic>, whose
contents are themselves subject to the same constraints).
Constructors
- Json(Object? value)
-
Create the given
valueas a JSON value. - Json.fromBool(bool value)
-
Create a JSON value containing the given
value.const - Json.fromDouble(double value)
-
Create a JSON value containing the given
value.const - Json.fromInt(int value)
-
Create a JSON value containing the given
value.const -
Json.fromList(List<
Json> value) -
Create a JSON value containing the given
value.const -
Json.fromMap(Map<
String, Json> value) -
Create a JSON value containing the given
value.const - Json.fromNull()
-
Create a JSON value containing null.
const
- Json.fromSource(String source)
-
Create a JSON value corresponding to the given
source. - Json.fromString(String value)
-
Create a JSON value containing the given
value.const
Properties
- asBool → bool
-
Get the bool value of this JSON value, or throw if other type.
no setter
- asBoolOrNull → bool?
-
Get the bool value of this JSON value, or null if other type.
no setter
- asDouble → double
-
Get the double value of this JSON value, or throw if other type.
no setter
- asDoubleOrNull → double?
-
Get the double value of this JSON value, or null if other type.
no setter
- asInt → int
-
Get the int value of this JSON value, or throw if other type.
no setter
- asIntOrNull → int?
-
Get the int value of this JSON value, or null if other type.
no setter
-
asList
→ List<
Json> -
Get the List value of this JSON value, or throw if other type.
no setter
-
asListOrNull
→ List<
Json> ? -
Get the List value of this JSON value, or null if other type.
no setter
-
asMap
→ Map<
String, Json> -
Get the Map value of this JSON value, throw if other type.
no setter
-
asMapOrNull
→ Map<
String, Json> ? -
Get the Map value of this JSON value, or null if other type.
no setter
- asString → String
-
Get the String value of this JSON value, or throw if other type.
no setter
- asStringOrNull → String?
-
Get the String value of this JSON value, or null if other type.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isBool → bool
-
Return true iff this JSON value is a bool.
no setter
- isDouble → bool
-
Return true iff this JSON value is a double.
no setter
- isInt → bool
-
Return true iff this JSON value is a int.
no setter
- isList → bool
-
Return true iff this JSON value is a List.
no setter
- isMap → bool
-
Return true iff this JSON value is a Map.
no setter
- isNull → bool
-
Return true iff this JSON value is null.
no setter
- isString → bool
-
Return true iff this JSON value is a String.
no setter
- isValid → bool
-
Validate this JSON value.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → Object?
-
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
split<
R> (R onNull(), R onBool(bool), R onInt(int), R onDouble(double), R onString(String), R onList(List< Json> ), R onMap(Map<String, Json> )) → R - Handle each possible shape of this JSON value.
-
splitNamed<
R> ({R onNull()?, R onBool(bool)?, R onInt(int)?, R onDouble(double)?, R onString(String)?, R onList(List< Json> )?, R onMap(Map<String, Json> )?, R onOther(Object?)?, R onInvalid(Object?)?}) → R? - Handle selected possible shapes of this JSON value.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
isDeepValid(
Json json) → bool -
Deeply validate the given
json.