Lucian Bumb Lucian Bumb -5 years ago 229
JSON Question

How to deserialize object with date in C#

I have this Json from a web api:

jsonstring ={"users":[{"id":1123,"last_update":"2016-02-28 14:53:04"}],"page":1,"pages":1}

which I want to deserialize in an object like:

public class Rootobject
public User[] users { get; set; }
public int page { get; set; }
public int pages { get; set; }

public class User
public int id { get; set; }
public DateTime last_update { get; set; }

for this I use:

var obj= JsonConvert.DeserializeObject<Rootobject>(jsonString);

the result has

is a string result from
; which look like above example.

How can I get the date on deserialization?


None of the solutions from this post Deserializing dates with dd/mm/yyyy format using Json.Net help me fix my issue.

Answer Source
var obj = JsonConvert.DeserializeObject<Rootobject>(jsonString, 
            new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download