✅ Deserializing nested array json file.
I am trying to get the json file data and store it in the class. But Storing in the class part doesnt work.
Weatherdata.current is null
12 Replies
can you paste some example json here?
I can see a few things that are likely wrong
one: its recommended to name your properties with C# standard names, and use
[JsonPropertyName]
to support snake-case names. For properties that just need to be Current
-> current
, thats easily fixed by just telling the serializer to use the web defaults
I'm fairly sure your problem is because your props in the root object are using pascal case, but you dont have web standards configured for your serializer
you should also pretty much never be using
a HttpClient
this is the whole json
thanks for the response. so should i change my props according to the file ?
no, you should tell your serializer to use web defaults.
Is it better in my case if i use restsharp
no. restsharp is garbage.
😄 alright
HttpClient
is all you need with GetFromJsonAsync
var response = await client.GetFromJsonAsync<ApiResponse>("...");
will do 99% of the job for youi
it will use web defaults, and you would need to change pretty much nothing else.. I personally would fix my response models to use proper C# naming and use attributes to "correct" the snake case names thoualright thank you so much trying to make it and changing the prop names rn
you should be able to implement the hourly stuff yourself 🙂
but see how easy it is when using the proper method on the client, just the one row
I really appreciate it man 😄
Just made the hourly 😃 thank you
Use the /close command to mark a forum thread as answered