decodeJson method
Reads and decodes content body as a JSON object, returned in a future.
The result is an object tree as parsed by the standard json.decode()
of
the dart:convert
package.
An optional reviver
function is applied when decoding json string data.
See JsonCodec
of the dart:convert
package for more information.
Throws ClientException if content body cannot be decoded as JSON.
Implementation
@override
Future<dynamic> decodeJson({
Object? Function(Object? key, Object? value)? reviver,
}) async {
try {
final res = response;
if (res is http.StreamedResponse) {
return json.decode(await res.stream.bytesToString(), reviver: reviver);
} else {
return json.decode((res as http.Response).body, reviver: reviver);
}
} on Exception catch (e) {
throw ClientException.decodingJsonFailed(e);
}
}