C
C#2y ago
adoma

❔ Why is my deserialize not working here:

private static void SearchGame() { Write("Title: "); string title = ReadLine(); HttpResponseMessage response = null; response = httpClient.GetAsync($"games/{title}").Result; response.EnsureSuccessStatusCode(); var content = response.Content.ReadAsStringAsync().Result; var games = JsonSerializer.Deserialize<List<GameDTO>>(content); foreach (var game in games) { WriteLine($"Id: {game.Id}"); WriteLine($"Title: {game.Title}"); WriteLine($"Description: {game.Description}"); WriteLine($"Release Date: {game.ReleaseDate}"); WriteLine($"Genre: {game.Genre}"); WriteLine($"Image URL: {game.ImageUrl}"); WriteLine(); } ReadKey(); Clear(); }
12 Replies
Buddy
Buddy2y ago
$details
MODiX
MODiX2y ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Buddy
Buddy2y ago
Include what error(s) you are getting, as well as the code without bad formatting And what result you are expecting
Pobiega
Pobiega2y ago
And show the json in content
adoma
adomaOP2y ago
im doing a Get request to this static readonly HttpClient httpClient = new HttpClient() { BaseAddress = new Uri("http://localhost:5000/api/") }; and it workes but the problem is that all the values is shown as null here WriteLine($"Id: {game.Id}");
WriteLine($"Title: {game.Title}"); WriteLine($"Description: {game.Description}"); WriteLine($"Release Date: {game.ReleaseDate}"); WriteLine($"Genre: {game.Genre}"); WriteLine($"Image URL: {game.ImageUrl}");
the result should be, when I search for the game it should show all the info like title, description, release date, genre and image url.
adoma
adomaOP2y ago
it's supposed to show this
adoma
adomaOP2y ago
but instead shows this
TheRanger
TheRanger2y ago
STJ is case sensitive, u either need to use Attribute JsonPropertyName on each property to specify which json property to take the value from or pass some json options argument with case insensitive on
TheRanger
TheRanger2y ago
How to enable case-insensitive property name matching with System.T...
Learn how to enable case-insensitive property name matching while serializing to and deserializing from JSON in .NET.
adoma
adomaOP2y ago
Tyvm, you're the best pepehands feel dumb now, don't know how I missed that. Done it on all the other methods except this.🤦‍♂️
Angius
Angius2y ago
Or you can tell STJ to not be case-sensitive
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server