I try to parse simple JSON using Json.net
string inputJson = @"
{
""modificationTime"" : ""\/Date(1224043200000)\/""
}";
And property is defined
[JsonProperty("modificationTime")]
[JsonConverter(typeof(JavaScriptDateTimeConverter))]
public DateTime ModificationTime { get; set; }
But DeserializeObject throw an exception with the following Message: "Unexpected token or value when parsing date. Token: Date, Value: 10/15/2008 04:00:00"
Well, as far as I see it actually has parsed the date, hasn't it? This exception is thrown from the line 68 in the JavaScriptDateTimeConverter.cs:
68 if (reader.TokenType != JsonToken.StartConstructor || string.Compare(reader.Value.ToString(), "Date", StringComparison.Ordinal) != 0)
69 throw new Exception("Unexpected token or value when parsing date. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
70
71 reader.Read();
In this place reader.TokenType is Date and reader.Value.ToString() is 10/15/2008 04:00:00. Any ideas?
Json.NET deserializes dates with the format:
"\/Date(1224043200000)\/"
by default. JavaScriptDateTimeConverter is for dates with the format:
new Date(1234567890)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With