Converting to DateTime in json.net
.net, c#, datetime, json, json.net
Solution
The format on your DateTime string uses a comma for the decimal separator (`,478`). You may be able to initialise a `JsonSerializerSettings` object (documented here) with an appropriate `Culture`, and then deserialise using `DeserializeObject<T>(value, settings)` (documented here). This would deserialise using the culture you specify rather than the default `InvariantCulture`.
Problem
I'm trying to deserialize the following: ``` {"ts":"2012-04-22 04:14:50,669", "msg":"Hello"} ``` into ``` public class LogEntry { public DateTime Ts { get; set; } public string Msg { get; set; } } ``` using ``` var logEntry = JsonConvert.DeserializeObject<LogEntry>(line); ``` But get a JsonSerializationException saying "{"Error converting value \"2012-04-22 04:14:28,478\" to type 'System.DateTime'. Line 1, position 31."}. I cannot change the log format. I think I might need to parse the date string myself using a Converter. However, I cannot find any examples of `JsonConverter` that seem relevant. Specifically how to read the value from the `reader` in the `ReadJson` method. Are there any simple examples that I should look at? Or am I going about this the wrong way?