Skip to content

Blazor - GetJsonAsync doesn't accept null in the json from API #17240

@shinhf

Description

@shinhf

Describe the bug

httpClient.GetJsonAsync is unable to parse JSON downloaded from API that contain null value

To Reproduce

@shipList

@code
{
    private List<Ship> shipList;
    HttpClient httpClient = new HttpClient() { BaseAddress = new Uri("https://api.spacexdata.com") };

    protected override async Task OnInitializedAsync()
    {
        shipList = await httpClient.GetJsonAsync<List<Ship>>("/v3/ships");

    }

Error value

InvalidOperationException: Cannot get the value of a token type 'Null' as a number.

Further technical details

  • ASP.NET Core version 3.0

PS
I've tried setting addJsonOptions in Startup.cs (https://stackoverflow.com/questions/44595027/net-core-remove-null-fields-from-api-json-response ) but it didn't work.

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions