CatAPI Json deserialization issue.
I'm having trouble getting my code to deserialize my json correctly. When I run my Program.cs I get
But I'm not able to access the fields in the json.
My Program.cs
my Json class
the response
my function
Does anyone know what I'm doing wrong?
7 Replies
The
[]
means the response is an array, so could be that
Also, why fiddle around with non-type-safe JsonDocument
and what not instead of just... parsing the response to JSON?Ahh Thank you! GetFromJsonAsync works so much better! The other way I was doing it was
which was pain.
yeah its returning an array of RandomCat, not just 1
it just happens to only be 1 item long
So you wanna do
JsonSerializer.Deserialize<RandomCat[]>
glad it works!
Even just one cat has 9 lives