I am wanting to build the C# data object to represent the following JSON. I am using unity's JsonUtility. I have used the JSONUtility before but only with a simpler JSON structure. However I am not sure nesting can be done as I have been searching for examples without any luck.
{
"datacharts":[{
"0000000009":[{
"dateTime": "2016-09-14 00:14:20",
"seconds": "60.50"
},
{
"dateTime": "2016-09-14 00:15:20",
"seconds": "57.23"
},{
"dateTime": "2016-09-14 00:18:20",
"seconds": "61.230"
},
{
"dateTime": "2016-09-14 00:23:20",
"seconds": "55.875"
}
]
}]
}
My current C# model.
[System.Serializable]
public struct Drivers
{
public DateTime[] dataTime; //time stamp unique enough to group each points?
public float[] seconds;
}
[System.Serializable]
public class DataCharts {
public List<Drivers> driverIds;
}
[System.Serializable]
public class DataList{
public List<DataCharts> availableData;
}
I'm not sure this answer will help me as I don't understand what it's wrapping. https://forum.unity3d.com/threads/how-to-load-an-array-with-jsonutility.375735/#post-2585129
Should my Json be modal differently? I am wanting to save driver times to display in a bar chart. So every driver would have a timestamp and the lap time.
UPDATE: after reading this question/answer Communicate Unity application via a series of Json
I've remodelled the json and c#. Json
{
"driverId": "0000000009",
"dataPoints": [{
"dateTime": "2016-09-14 00:14:20",
"seconds": "60.50"
},{
"dateTime": "2016-09-14 00:15:20",
"seconds": "57.23"
},{
"dateTime": "2016-09-14 00:18:20",
"seconds": "61.230"
},
{
"dateTime": "2016-09-14 00:23:20",
"seconds": "55.875"
}]
}
C#
[Serializable]
public struct Drivers
{
public string driverId;
public List<DataPoints> points;
}
[Serializable]
public class DataPoints {
public string dateTime;
public string seconds;
}
[Serializable]
public class DataList{
public List<Drivers> availableData;
}