C
C#3y ago
maria 🌟

❔ Null exception

22 Replies
maria 🌟
maria 🌟OP3y ago
I know thath some times thath will be null but i dont want an exception to ocurres
Thinker
Thinker3y ago
What are you doing? What are you deserializing?
maria 🌟
maria 🌟OP3y ago
response of server
Thinker
Thinker3y ago
Deserialize the response to a class Do not use dynamic
maria 🌟
maria 🌟OP3y ago
i prefere JsonNode :c
Thinker
Thinker3y ago
Do NOT use dynamic
maria 🌟
maria 🌟OP3y ago
why 😰
Thinker
Thinker3y ago
Because dynamic disables all type safety. This means you won't get any intellisense, any type hints, any compile-time safety, etc.
maria 🌟
maria 🌟OP3y ago
Tell me why Ain't nothin' but a heartache
Thinker
Thinker3y ago
Dynamic is capital B Bad in 99.999% of cases It should not be used unless there is a very very very good reason This is not one of them
maria 🌟
maria 🌟OP3y ago
i dont know the whole response of the server :/
Thinker
Thinker3y ago
What server is it?
maria 🌟
maria 🌟OP3y ago
im scraping the api of my router to make an watcher of the cpu and ram of my router on real time
Thinker
Thinker3y ago
of your router...?
maria 🌟
maria 🌟OP3y ago
and then make analitycs yea 😃 modem but i guess i will just ad and try catch :C
Thinker
Thinker3y ago
Well, you should still be deserializing to a class for the information you do know
maria 🌟
maria 🌟OP3y ago
yes but
Thinker
Thinker3y ago
Paste your JSON into $jsongen
MODiX
MODiX3y 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.
maria 🌟
maria 🌟OP3y ago
but some times changes idk my router is kinda sus
Thinker
Thinker3y ago
These automatically generate classes from your JSON that definitely seems sus
Accord
Accord3y 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.

Did you find this page helpful?