I am trying to deserialize an object with the following code, and I am wondering which correct regular expression will replace json dates. When I run the following code, the regular expression never runs. I am using the standard JSON date format inside the json string.
{ "UniqueId": "1000000003", "Id": 3, "ModifyTimestamp": "/Date(1338857699743)/" } string json = // see above string p = @"\\/Date\((\d+)\+\d+\)\\/"; MatchEvaluator matchEvaluator = new MatchEvaluator(convertJsonDateToDateString); Regex reg = new Regex(p); json = reg.Replace(json, matchEvaluator); JavaScriptSerializer serializer = new JavaScriptSerializer(); Student student = serializer.Deserialize<Student>(json) as Student; public static string convertJsonDateToDateString(Match m) { string result = string.Empty; DateTime dt = new DateTime(1970, 1, 1); dt = dt.AddMilliseconds(long.Parse(m.Groups[1].Value)); dt = dt.ToLocalTime(); result = dt.ToString("yyyy-MM-dd HH:mm:ss"); return result; }
source share