I am trying to serialize a JSON result from an API. The result has the following structure:
{
"Version" : "123",
"Message" : "some string",
"Status" : 200,
"Result" : {
"Events" : [ {"Subprop1" : "some_value"}, {"Subprop2" : "some_value"} ],
"Merch" : [ {"Subprop2" : "some_value"}, {"Subprop2" : "some_value"} ],
"Tickets" : [ {"Subprop3" : "some_value"}, {"Subprop2" : "some_value"} ],
"Seasons" : [ {"Subprop4" : "some_value"}, {"Subprop2" : "some_value"} ]
}
}
My question is: how do I deserialize this properly into objects of the classes I made ? I've made classes for each of Result's proprieties (i.e. Event, Merch etc)
My code so far:
dynamic resultJSON = JsonConvert.DeserializeObject<dynamic>(response.Content);
dynamic data = resultJSON.Result;
Newtonsoft.Json.Linq.JArray events = resultJSON.Result.Events;
resultJSON
contains everything in an object. How do I deserialize this in their own classes? And avoid JArray
Update here is my Event
class
public class Event
{
public int OrderId { get; set; }
public int Id { get; set; }
public string Name{ get; set; }
public string Type { get; set; }
}
public class ListEvents
{
public List<Event> Events { get; set; }
}