Based on the code you have provided, the response body is encoded as
JSON[
^].
You use
ReadAsBytesAsync
to load the response into an array of bytes. You could alternatively use
ReadAsStringAsync
to get a string, or
ReadAsStreamAsync
to get a
Stream
. In this case, you're getting an array of bytes because that's what your
JsonSerializer.Deserialize
method wants.
As an alternative:
In .NET Framework and .NET Core, you could add a reference to the
Microsoft.AspNet.WebApi.Client
NuGet package, and use
ReadAsAsync<IEnumerable<Order>>
to automatically deserialize the JSON for you.
In .NET 5, this seems to have been replaced with the
ReadFromJsonAsync<IEnumerable<Order>>
extension method, defined in
System.Net.Http.Json.HttpContentJsonExtensions
.