I am trying to deserialize the following:
{"ts":"2012-04-22 04:14:50,669", "msg":"Hello"}
at
public class LogEntry
{
public DateTime Ts { get; set; }
public string Msg { get; set; }
}
using
var logEntry = JsonConvert.DeserializeObject<LogEntry>(line);
But get a JsonSerializationException that says: "{" Error converting value "2012-04-22 04:14:28,478 \" to enter "System.DateTime". Line 1, position 31. "}. I cannot change the format of the log.
I think that I may need to parse the date string myself using a converter. However, I cannot find examples JsonConverterthat seem relevant. In particular, how to read the value from readerin the method ReadJson.
Are there any simple examples I should look at? Or am I mistaken about this?
source
share