json学习笔记(5)
Regex rg = new Regex(p);
jsonstring = rg.Replace(jsonstring, me);
DataContractJsonSerializer zer = new DataContractJsonSerializer(typeof(T));
MemoryStream ms=new MemoryStream(Encoding.UTF8.GetBytes(jsonstring));
T obj = (T)zer.ReadObject(ms);
return obj;
}
/// <summary>
/// 将Json序列化的时间由/Date(1294499956278+0800)转为字符串
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
private 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;
}
/// <summary>
/// 将时间字符串转化成json时间
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
private static string ConvertDateTimeToJsonDate(Match m)
{
string result = string.Empty;
DateTime dt = DateTime.Parse(m.Groups[0].Value);
dt = dt.ToUniversalTime();
TimeSpan ts = dt - DateTime.Parse("1970-01-01");
result = string.Format("\\/Date({0}+0800)\\/",ts.TotalMilliseconds);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>