skip to Main Content

Json – What's the best way to get result from ReadAsStringAsync response?

What I have This code calling my API: HttpResponseMessage response = await Http.GetAsync("https://localhost:7094/api/MyResource/94d0e5ca-2be7-42f7-94dc-13955c11595c"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine($"RESPONSE: {responseBody}"); var payload = JsonSerializer.Deserialize<MyClass>(responseBody); var json = JsonSerializer.Serialize(payload); Console.WriteLine($"PAYLOAD: {json}"); This code is called from OnInitializedAsync in a NET8…

VIEW QUESTION

C# JsonDocument.Parse() Auto casting

I'm coding using C#. When GET request, I get json format string like { "code": 2312, "price": 98.322, ... } to parse, I use System.Text.Json.JsonDocument.Parse(jsonString) function. I think they're type-casting internally. But because of the floating-point error, I want JsonDocument.Parser…

VIEW QUESTION
Back To Top
Search