From 78db927720a83891d34fb74ec64dafb58064c6df Mon Sep 17 00:00:00 2001 From: Michael <44764541+cmos12345@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:38:13 +0200 Subject: [PATCH] Fixed rendering of numeric double values (#453) --- .../JsonTreeView/MudJsonTreeViewNode.razor | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CodeBeam.MudBlazor.Extensions/Components/JsonTreeView/MudJsonTreeViewNode.razor b/CodeBeam.MudBlazor.Extensions/Components/JsonTreeView/MudJsonTreeViewNode.razor index 65fd6835..a744e506 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/JsonTreeView/MudJsonTreeViewNode.razor +++ b/CodeBeam.MudBlazor.Extensions/Components/JsonTreeView/MudJsonTreeViewNode.razor @@ -34,8 +34,18 @@ } break; case JsonValueKind.Number: - var number = child.Value.AsValue().GetValue(); - + JsonValue jsonVal = child.Value.AsValue(); + string endText = string.Empty; + @* We try for int first, because an int can always be converted to double but not the other way around*@ + if (jsonVal.TryGetValue(out int intVal)) + { + endText = intVal.ToString(); + } + else if (jsonVal.TryGetValue(out double doubleVal)) + { + endText = doubleVal.ToString(); + } + break; case JsonValueKind.True: