C
C#16mo ago
big OOF

❔ Dezerialise JSON response

Example: person { 18370101 (changing social security number) {
name: name, age: age description: "<p> This is a person with name and age </p>" } }
I want to dezerialise the json response into <Person> but the social security number dosent belong to a json property. From what i understand you can use something called Jtoken to solve this but it dosent feel quite right. Are there any alternatives? Also the field description contains html-elements, when im trying to dezerialise it throws an error, one again - any ideas? 🙂 Thanks in advance!
7 Replies
Anton
Anton16mo ago
the example you typed isn't a valid json
Denis
Denis16mo ago
Are you creating the JSON manually, or is it provided by some API? Just like mentioned by Anton, it is invalid json
Angius
Angius16mo ago
$jsongen
MODiX
MODiX16mo ago
Use https://app.quicktype.io or https://json2csharp.com to generate classes from your JSON
Instantly parse JSON in any language | quicktype
Whether you're using C#, Swift, TypeScript, Go, C++ or other languages, quicktype generates models and helper code for quickly and safely reading JSON in your apps. Customize online with advanced options, or download a command-line tool.
Convert JSON to C# Classes Online - Json2CSharp Toolkit
Convert any JSON object to C# classes online. Json2CSharp is a free toolkit that will help you generate C# classes on the fly.
big OOF
big OOF16mo ago
I just created the JSON above as an example but in relity it do come from an API. When creating the Perosn class i used "paste as JSON" in visual studio 🙂
SG97
SG9716mo ago
it would help if you provide an actually valid json though leaving out properties during deserialization should not be a problem
Accord
Accord16mo 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
More Posts