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?