In a C# project, I'm retrieving an Event object, with subject (string), location (string), start_time (datetime), end_time (datetime), all_day_event (boolean) and calendar_id (int) properties, as a JSON response from a Rest request. That request gets data from a database and start_time and end_time columns' types are datetime on that database too. But I'm having trouble about getting the datetime type values. I get the JSON object like this:
[
{
"id": 1,
"subject": "Test Event 1",
"location": "Test Location",
"start_time": "2019-08-22 10:17:53",
"end_time": "2019-08-22 10:17:55",
"all_day_event": 0,
"calendar_id": 1
}
]
This is my Event class:
public class Event {
public int Id { get; set; }
public string Subject { get; set; }
public string Location { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public bool AllDayEvent { get; set; }
public int CalendarId { get; set; }
}
And this is how I deserialize the JSON object:
events = JsonConvert.DeserializeObject<Event[]>(response.Content);
When I print that JSON object directly, it is displayed correctly. But after I deserialize it, the time values are displayed as 01/01/0001 12:00 AM. I've searched for a while. I've found Deserialize Json Object - DateTime, Deserializing Import Io JSON with multiple objects, Deserialize multiple json into object c# suggestions but they didn't help. So is there any way to get those time values properly?? Thank you so much.
[JsonProperty("start_time")]attribute toStartTimeproperty