C
C#2y ago
skyferian

maui deserialize problem

I am having a problem when trying to deserialize api data
C#
string content = await response.Content.ReadAsStringAsync();
Debug.WriteLine("content -->");
Debug.WriteLine(content);

mylists = JsonSerializer.Deserialize<List<Item>>(content, _jsonSerializerOptions);
Debug.WriteLine(mylists);
C#
string content = await response.Content.ReadAsStringAsync();
Debug.WriteLine("content -->");
Debug.WriteLine(content);

mylists = JsonSerializer.Deserialize<List<Item>>(content, _jsonSerializerOptions);
Debug.WriteLine(mylists);
// this is what content says [{"id":1,"name":"Paprika chips","brand":"Lays","store":"Aldi"},{"id":2,"name":"producttest","brand":"brandttest","store":"Lidl"} so this one is correct but only the deserialize gives me some kind of problem and i do not understand why this is what mylists says System.Collections.Generic.List`1[Boodschappenlijst.Model.Item]
C#
public class Item
{
public int Id { get; set; }
public string name { get; set; }
public string brand { get; set; }
public string store { get; set; }
}
C#
public class Item
{
public int Id { get; set; }
public string name { get; set; }
public string brand { get; set; }
public string store { get; set; }
}
10 Replies
sibber
sibber2y ago
JsonSerializer is case sensitive by default also .ToString() returns the type by default it doesnt return the contents of the list you can use string.Join for that or even better, use the debugger
skyferian
skyferian2y ago
SO bassicaly the I in Id and what do you mean with use the debugger
sibber
sibber2y ago
put a breakpoint after deserializing and check the contents of list rather than logging
skyferian
skyferian2y ago
oh okey
sibber
sibber2y ago
JsonSerializerOptions.PropertyNamingPolicy Property (System.Text.Json)
Gets or sets a value that specifies the policy used to convert a property's name on an object to another format, such as camel-casing, or null to leave property names unchanged.
sibber
sibber2y ago
so you can use PascalCase for the class properties in c#
skyferian
skyferian2y ago
i see now bassicaly i was just printing the type instead of the data
sibber
sibber2y ago
yup also use PascalCase for propertie names :)
skyferian
skyferian2y ago
thank you for your help and yes i forgot you are right
sibber
sibber2y ago
np
Want results from more Discord servers?
Add your server
More Posts
❔ Log from helper class without creating new context? (Serilog)I have a bunch of services with their own dedicated loggers that have config'd settings for filterin❔ Swagger Open API not showing Request examples in the UII've written an Azure Function with Open API in C#, but when I open up the Swagger/UI to test my AzuLooking solution for get query from _dbContext.SaveChangesAsync() for save logs and easier debuggingHello, i have a .net core 6.0 app that save entites in MSSQL database with EfCORE 6.0 so my function❔ I'm building an MVC core webshop. How should I be structuring controllers, actions and views?So, right now, I have one single view, and this view renders both information about the product and ❔ How to make an object follows my mouse?so I am new at programming and trying to make a top down shooting games in windows form app. My lect❔ Is this the right way to implement an Interface```csharp interface IObstacles { void Draw(Graphics g); } class Redbox : IO❔ Is there any tool converting csv file to Class (seeding data)?I am using EF to seed data and I have an excel file containing like 500 records. If that's around 1❔ Is it possible to have WPF window hidden until Blazor WebView loads page?I'm trying to hide a WPF window until the Blazor WebView loads, but it seems that the initialization❔ SQLite in-memory Database read from ReadOnlyMemory bytesI'm receiving an SQLite database payload from an AMQP-0-9-1 message in the form of `ReadOnlyMemory<bSettings.Default not savingI have two integers, primary and secondary, that i want to persist, but they refuse to