C#C
C#9mo ago
Theos

Issue when deserializing web response

Hey, I'm making a simple call to the api and looking at the text reponse it looks correct (check first image).
HttpResponseMessage response = await client.GetAsync(nextPageUrl);
string responseBody = await response.Content.ReadAsStringAsync();

if (response.IsSuccessStatusCode)
{
    var animeListResponse = JsonSerializer.Deserialize<AnimeListResponse>(responseBody,
        new JsonSerializerOptions { PropertyNameCaseInsensitive = true });

    if (animeListResponse.Data != null)
    {
        animeList.AddRange(animeListResponse.Data);
    }


For some reason ListStatus is always null (look at second image)

public class AnimeListResponse
{
    public AnimeData[] Data { get; set; }
    public Paging Paging { get; set; }
}

public class AnimeData
{
    public AnimeNode Node { get; set; }
    public ListStatus ListStatus { get; set; }
}

public class AnimeNode
{
    public int Id { get; set; }
    public string Title { get; set; }
}

public class ListStatus
{
    [JsonPropertyName("status")]
    public string Status { get; set; }

    [JsonPropertyName("score")]
    public int Score { get; set; }

    [JsonPropertyName("num_episodes_watched")]
    public int Num_Episodes_Watched { get; set; }
}
image.png
image.png
Was this page helpful?