jsonDecode function
Parses the string and returns the resulting Json object.
The optional reviver
function is called once for each object or list
property that has been parsed during decoding. The key
argument is either
the integer list index for a list property, the string map key for object
properties, or null
for the final result.
The default reviver
(when not provided) is the identity function.
Shorthand for json.decode
. Useful if a local variable shadows the global
json constant.
Example:
const jsonString =
'{"text": "foo", "value": 1, "status": false, "extra": null}';
final data = jsonDecode(jsonString);
print(data['text']); // foo
print(data['value']); // 1
print(data['status']); // false
print(data['extra']); // null
const jsonArray = '''
[{"text": "foo", "value": 1, "status": true},
{"text": "bar", "value": 2, "status": false}]
''';
final List<dynamic> dataList = jsonDecode(jsonArray);
print(dataList[0]); // {text: foo, value: 1, status: true}
print(dataList[1]); // {text: bar, value: 2, status: false}
final item = dataList[0];
print(item['text']); // foo
print(item['value']); // 1
print(item['status']); // false
Implementation
dynamic jsonDecode(
String source, {
Object? reviver(Object? key, Object? value)?,
}) => json.decode(source, reviver: reviver);