验证中...
开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约
语言: C#
分类: 常用工具包
最后更新于 2018-12-09 10:07
gistfile1.txt
原始数据 复制代码
public static string ToJson(object obj)
{
string str = string.Empty;
JavaScriptSerializer serializer = new JavaScriptSerializer();
str = serializer.Serialize(obj);
//\/Date(-2209017600000)\/
str = Regex.Replace(str, @"\\/Date\((-?\d+)\)\\/", match =>
{
DateTime dt = new DateTime(1970, 1, 1);
dt = dt.AddMilliseconds(long.Parse(match.Groups[1].Value));
dt = dt.ToLocalTime();
return dt.ToString("yyyy-MM-dd HH:mm:ss");
});
str = Regex.Replace(str, @"null", match =>
{
return "\"\"";
});
return str;
}
public static List<T> JsonToList<T>(string jsonStr)
{
List<T> jObject = null;
try
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
jObject = serializer.Deserialize<List<T>>(jsonStr);
}
catch (Exception)
{
throw;
}
return jObject;
}

评论列表( 1 )

1622646_peacezhi
和平小智 2018-03-23 17:39

很有用处 :+1:

你可以在登录后,发表评论

搜索帮助