C
C#16mo ago
maria 🌟

❔ Null exception

22 Replies
maria 🌟
maria 🌟16mo ago
I know thath some times thath will be null but i dont want an exception to ocurres
Thinker
Thinker16mo ago
What are you doing? What are you deserializing?
maria 🌟
maria 🌟16mo ago
response of server
Thinker
Thinker16mo ago
Deserialize the response to a class Do not use dynamic
maria 🌟
maria 🌟16mo ago
i prefere JsonNode :c
Thinker
Thinker16mo ago
Do NOT use dynamic
maria 🌟
maria 🌟16mo ago
why 😰
Thinker
Thinker16mo 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 🌟16mo ago
Tell me why Ain't nothin' but a heartache
Thinker
Thinker16mo 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 🌟16mo ago
i dont know the whole response of the server :/
Thinker
Thinker16mo ago
What server is it?
maria 🌟
maria 🌟16mo ago
im scraping the api of my router to make an watcher of the cpu and ram of my router on real time
Thinker
Thinker16mo ago
of your router...?
maria 🌟
maria 🌟16mo ago
and then make analitycs yea 😃 modem but i guess i will just ad and try catch :C
Thinker
Thinker16mo ago
Well, you should still be deserializing to a class for the information you do know
maria 🌟
maria 🌟16mo ago
yes but
Thinker
Thinker16mo ago
Paste your JSON into $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.
maria 🌟
maria 🌟16mo ago
but some times changes idk my router is kinda sus
Thinker
Thinker16mo ago
These automatically generate classes from your JSON that definitely seems sus
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.