I'm currently trying to convert a JSON string into C# objects and currently am experiencing trouble during my debugging. Below is a sample of the JSON along with my classes.
Classes
public class Timeline_RootObject
{
public List<Timeline_Frame> frames { get; set; }
public int frameInterval { get; set; }
}
public class Timeline_Frame
{
public Participants players { get; set; }
public IList<Event> events { get; set; }
public int timestamp { get; set; }
}
public class Participants
{
public Players player1{ get; set; }
public Players player2 { get; set; }
}
public class Event_Position
{
public int x { get; set; }
public int y { get; set; }
}
public class Player_Position
{
public int x { get; set; }
public int y { get; set; }
}
public class Players
{
public int participantId { get; set; }
public Player_Position position { get; set; }
public int currentGold { get; set; }
}
public class Event
{
public string type { get; set; }
public int timestamp { get; set; }
public int participantId { get; set; }
public int itemId { get; set; }
}
Sample JSON
{"frames": [
{
"participantFrames": {
"player1": {
"participantId": 1,
"position": {
"x": 561,
"y": 581
},
"currentGold": 475
},
{
"player2": {
"participantId": 2,
"position": {
"x": 561,
"y": 581
},
"currentGold": 475
}
},
"events": [
{
"type": "ITEM_PURCHASED",
"timestamp": 1829,
"participantId": 1,
"itemId": 1039
}
],
"timestamp": 0
},
{
"participantFrames": {
"player1": {
"participantId": 1,
"position": {
"x": 800,
"y": 681
},
"currentGold": 525
},
{
"player2": {
"participantId": 2,
"position": {
"x": 754,
"y": 642
},
"currentGold": 525
}
},
"events": [
{
"type": "ITEM_PURCHASED",
"timestamp": 45358,
"participantId": 1,
"itemId": 684
}
],
"timestamp": 60000
}
Currently I am able to access the Event's Type, Timestamp, ItemID and participant ID. But for some reason I can't access classes within a class for example the Event_Position or Players class is always null.
Code Generating Objects
public List<Timeline_RootObject> json_timeline = new List<Timeline_RootObject>();
json_timeline.Add(JsonConvert.DeserializeObject<Timeline_RootObject>(json));
If anybody could help guide me through this small roadblock, I'd greatly appreciate it!