JavaScriptConverter

public class DatePartsConverter : JavaScriptConverter
{
public override IEnumerable<Type> SupportedTypes
{
get { yield return typeof(DateTime); }
} public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
if (obj is DateTime)
{
DateTime date = (DateTime)obj; var json = new Dictionary<string, object>(); json["year"] = date.Year;
json["month"] = date.Month;
json["day"] = date.Day; return json;
} return null;
} public override object Deserialize(IDictionary<string, object> json, Type type, JavaScriptSerializer serializer)
{
if (type == typeof(DateTime))
{
object year, month, day; json.TryGetValue("year", out year);
json.TryGetValue("month", out month);
json.TryGetvalue("day", out day); if ((year is int)
&& (month is int)
&& (day is int))
return new DateTime((int)year, (int)month, (int)day);
} return null;
}
}
上一篇:粗化精确匹配CEM文献推荐, 程序步骤可复制


下一篇:kali下利用weeman进行网页钓鱼