I'm new at JSON and I'm learning so excuse me if I'm being ignorant. I have the following JSON:
"data": [
{
"id": 373644788,
"description": "something ",
"start": "2016-04-28T02:23:01+02:00",
"end": "2016-04-28T02:23:12+02:00",
"updated": "2016-04-28T02:24:05+02:00",
"dur": 11000,
"user": "John Smith",
"project": "First Project",
},
{
"id": 373635064,
"description": "None",
"start": "2016-04-28T01:43:42+02:00",
"end": "2016-04-28T01:44:06+02:00",
"updated": "2016-04-28T01:44:21+02:00",
"dur": 24000,
"user": "Drake",
"project": "Second Project",
}]
Each of these JSON objects, which are inside the array is a separate project and I need to extract the data (ID, Name, Start, End) from each one and put them into my C# Class and they should be stored separately for each project because they will be later exported into a database which has the same columns as these properties.
I created the Class Definitions:
public class Definitions
{
public int id { get; }
public string user { get; }
public double dur { get; }
public string project { get; }
public override string ToString()
{
return string.Format("ID: {0}, Name: {1}, Duration: {2}, Projekt: {3}", this.id, this.user, this.dur, this.project);
}
The problem is that I can't access the properties inside my JSON.If I try to Deserialize it I get always 0 in my output on all my properties, as if I can't access these properties.
And the second question is how can I store them? I mean when they are exported to the database each of them should be automatically put into separate rows with each row having (ID,Nama,Start,End) columns.
Thank you.
Deserilize:
String jsonString = File.ReadAllText(@"D:\Json.json");
Definitions def = JsonConvert.DeserializeObject<Definitions>(jsonString);
Console.WriteLine(def);