C
C#2y ago
Kosta

❔ How do i enumarate this?

Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var sales = JsonSerializer.DeserializeAsyncEnumerable<Sales>(
responseStream,
new JsonSerializerOptions
{
DefaultBufferSize = 16384

});
Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var sales = JsonSerializer.DeserializeAsyncEnumerable<Sales>(
responseStream,
new JsonSerializerOptions
{
DefaultBufferSize = 16384

});
No foreeach possible
4 Replies
HimmDawg
HimmDawg2y ago
Why is foreach not possible? fluffyFoxThink what is "this" referring to? The sales object? A property of sales? If you want to enumerate over sales, then you have to implement IEnumerable<>
Sossenbinder
Sossenbinder2y ago
JsonSerializer.DeserializeAsyncEnumerable Method (System.Text.Json)
Wraps the UTF-8 encoded text into an IAsyncEnumerable that can be used to deserialize root-level JSON arrays in a streaming manner.
Sossenbinder
Sossenbinder2y ago
So to enumerate that, you need to use await foreach
await foreach (var sale in sales)
{
...
}
await foreach (var sale in sales)
{
...
}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.