views:

411

answers:

2

I've been searching through the web to look for a solution for this but still stuck.

I'm having difficulties serializing DateTime object. The standard serialize using DataContract will give this result \/Date(1262600239000)\/. After Ext.encode the result changed to /Date(1262600239000)/. The result from Ext.encode is not readable in ExtJS date related components such as DateField and ColumnModel for date.

As for deserializing, i'd have to provide the date in this \/Date(1262600239000)\/ format in order to deserialize the date. How can i achive this with the ExtJS DateField?

Is there any specific ways to get around this?

Thanks in advance.

A: 

Have you tried this?

It's an override for ExtJS' JSON encode and decode methods. Make sure to read the last comment as well.

brianng
i've tried this method and it works... but it gives another problem... The Ext.decode decodes my tree json incorrectly... As for reference this is my post in ExtJS Forumhttp://www.extjs.com/forum/showthread.php?p=424408#post424408
osheh
+1  A: 

You could try Newtonsoft Json.NET. It's open source and free (MIT license).

It is the one used by the Ext.Direct .NET Router which was developed by Evant (who is part of ExtJS Core Development Team).

You can see this code that uses it for a DateTime in the sample of Ext.Direct .NET Router:

[JsonObject]
public class Company {
    //...
    [JsonProperty(PropertyName = "started")]
    [JsonConverter(typeof(IsoDateTimeConverter))]
    public DateTime Started { get; set; }
    //...
}
Protron