日期:2014-05-18 浏览次数:20542 次
//Model public class Model { public datetime DT{get;set;} public string Name{get;set;} } //--------- //xx.ashx文件 List<Model> listmodel={xxxxxxx}; if (file.Count() != 0) { System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer(); string jsonStr = json.Serialize(listmodel); context.Response.Write(jsonStr); }
$.post("xxx.ashx", { "Name": cname, "Type": "customer" }, function(data) { if (data != "False") { for(var i=0;i<data.length;i++) { var d=data[i].Time; //这里获取的值,不再是时间。。据说要反序列化,额,求个函数 } } },"JSON");
//获取序列化后的字符串,然后通过正则获取Date中的部分,在去进行转换。 protected string JsonDateToDateString(string str) { Regex reg = new Regex(@"\\/Date\((\d+)\+\d+\)\\/"); string time = reg.Match(str).Groups[1].Value; DateTime dt = new DateTime(1970, 1, 1); dt = dt.AddMilliseconds(long.Parse(time)); dt = dt.ToLocalTime(); return reg.Replace(str, dt.ToString("yyyy-MM-dd HH:mm:ss")); }
------解决方案--------------------
取到的值是这样形式." /Date(1323100800000+0800)/" var Dtime =" /Date(1323100800000+0800)/"; var NewDtime = new Date(parseInt(Dtime.slice(6, 19))); var Dyear = NewDtime.getFullYear(); var Dmonth = NewDtime.getMonth() + 1; var Ddate = NewDtime.getDate();