Newtonsoft.Json json handling
i got a message like "Rooms":{"room1", "room2"}
how can i deserialize such message?
preferably put it in some sort of array/list
13 Replies
tried making this class to hold the data
but jsonConvert.Deserialize (i dont remember the full command lol) just crashes
The message you posted is not valid json.
If you do indeed have json, you should use
System.Text.Json
and consult this page for an easy way in VS to create the target class:
https://learn.microsoft.com/en-us/visualstudio/ide/reference/paste-json-xml?view=vs-2022Paste JSON or XML as classes - Visual Studio (Windows)
Learn how to copy any JSON or XML text from the clipboard and then paste it as .NET classes into C# or Visual Basic code.
Then use
System.Text.Json.Serializer.Deserialize<RoomData>(jsonString)
i mightve not read it correctly, let me re-run it
Newtonsoft.Json
was obsoleted by System.Text.Json
and should not be used in new projects.aw nahh my partner fucked up the serialization in c++ 😭
well i guess i can make Rooms a string and just split it
okay its working nevermind
thank you for making me check lmao
Newtonsoft.Json is not recommended anymore as the default json class in C# is already more than capable
As the people above have already stated, switch to
System.Text.Json
. After that, you can incorporate something similar to this:
yeah lol, i didnt read the text i was getting correctly
ive fixed it though
👍