Hello how can I deserialize the following JSON structure with VB.NET?
{
"ok": true,
"license": "CC BY 4.0",
"data": "TEST",
"stations": {
"station1": {
"status": "open",
"price1": 1.234,
"price2": 1.234,
"price3": 1.234
},
"station2": {
"status": "open",
"price1": 1.234,
"price2": 1.234,
"price3": 1.234
}
}
}
Important the number of stations could be different. Here in this example are two stations.
Thank you very much.
Visual Studio has a cool feature called Paste JSON as Classes that can be found under Edit > Paste Special > Paste JSON as Classes. Using either Newtonsoft.Json or System.Text.Json, you can tidy the classes up a little bit using decorators so that you can conform to .NET standard naming conventions while still serializing the JSON to the expected values.
This is how the class definitions would look tidied up a bit:
Now all you need to do is call the DeserializeObject method, using your Response class as the type and passing your JSON literal. For example: