I'm trying to read a list of objects from a public WEB Api that provides a JSON file with an array of objects, I'm using Blazor and the Net 5 platform.
The de-serialization fails with this error:
System.Text.Json.JsonException: The JSON value could not be converted to Meme[].
I suspect I'm modeling the "receiving" object incorrectly, should I change my code or use other libraries for this code to succeed?
The Api can be found at this endpoint, I tried reading the response in these two ways:
var response = await Http.GetFromJsonAsync<Meme[]>("https://api.imgflip.com/get_memes");
and
var httpResponse = await Http.GetAsync("https://api.imgflip.com/get_memes");
var response = await httpResponse.Content.ReadFromJsonAsync<Meme[]>();
the Meme class is declared as such:
public string Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int BoxCount { get; set; }
and the response should contain this content:
"success": true,
"data": {
"memes": [
{
"id": "181913649",
"name": "Drake Hotline Bling",
"url": "https://i.imgflip.com/30b1gx.jpg",
"width": 1200,
"height": 1200,
"box_count": 2
},
{
...
},
... ]
}
These are the libraries I'm including:
using System.Net.Http;
using System.Net.Http.Json;