开发者

deserialize "/Date(1309498021672)/" in to DateTime

开发者 https://www.devze.com 2023-03-16 17:00 出处:网络
I have a object that I serialize with the JavaScriptSerializer and output it in a javascript variable.

I have a object that I serialize with the JavaScriptSerializer and output it in a javascript variable.

A property on this object is a date which gets converted to eg. "/Date(1309498021672)/"

I then send this value to the server via a ui wcf service call. I want to deserialize this value in to a DateTime object.

How can I do t开发者_如何学编程his? I am working with asp.net c# web application.


Your string format is just a little off, but this will deserialize to a proper date.

var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string json = "\"\\/Date(1309498021672)\\/\"";
DateTime date = serializer.Deserialize<DateTime>(json);
// date is 7/1/2011 5:27:01 AM
0

精彩评论

暂无评论...
验证码 换一张
取 消