-
-
Save Ershad95/7c21599d16e129f83ced744acd529315 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int TARGET = 80; | |
var _httpClient = new HttpClient(); | |
using (var response = await _httpClient.GetAsync( | |
"https://localhost:7284/customer", | |
HttpCompletionOption.ResponseHeadersRead)) | |
{ | |
var stream = await response.Content.ReadAsStreamAsync(); | |
var _jsonSerializerSettings = new JsonSerializerSettings(); | |
var _serializer = Newtonsoft.Json.JsonSerializer.Create(_jsonSerializerSettings); | |
using TextReader textReader = new StreamReader(stream); | |
using JsonReader jsonReader = new JsonTextReader(textReader); | |
await using (stream.ConfigureAwait(false)) | |
{ | |
await jsonReader.ReadAsync().ConfigureAwait(false); | |
while (await jsonReader.ReadAsync().ConfigureAwait(false) && | |
jsonReader.TokenType != JsonToken.EndArray) | |
{ | |
Customer customer = _serializer!.Deserialize<Customer>(jsonReader); | |
if (customer.Id == TARGET) | |
{ | |
Console.WriteLine(customer.Id + " : " + customer.Name); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment