无法使用JavaScriptDateTimeConverter解析数据

Kir*_*kov 6 c# json json.net

我尝试使用Json.net解析简单的JSON

 string inputJson = @"
                {
                 ""modificationTime"" : ""\/Date(1224043200000)\/""
                 }";
Run Code Online (Sandbox Code Playgroud)

财产是定义的

[JsonProperty("modificationTime")]
[JsonConverter(typeof(JavaScriptDateTimeConverter))]
public DateTime ModificationTime { get; set; }
Run Code Online (Sandbox Code Playgroud)

但DeserializeObject使用以下消息抛出异常:"解析日期时出现意外的标记或值.令牌:日期,值:10/15/2008 04:00:00"

好吧,据我所知它实际上已经解析了日期,不是吗?从JavaScriptDateTimeConverter.cs中的第68行抛出此异常:

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();
Run Code Online (Sandbox Code Playgroud)

在这个地方reader.TokenType是Date和reader.Value.ToString()是10/15/2008 04:00:00.有任何想法吗?

Jam*_*ing 7

Json.NET使用以下格式反序列化日期:

"\/Date(1224043200000)\/"
Run Code Online (Sandbox Code Playgroud)

默认情况下.JavaScriptDateTimeConverter适用于格式为的日期:

new Date(1234567890)
Run Code Online (Sandbox Code Playgroud)