CustomJsonConverter.cs 828 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Web.Script.Serialization;
  6. public class CustomJsonConverter : JavaScriptConverter
  7. {
  8. public override IEnumerable<Type> SupportedTypes
  9. {
  10. get { return new[] { typeof(DateTime) }; }
  11. }
  12. public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
  13. {
  14. var result = new Dictionary<string, object>();
  15. if (obj is DateTime)
  16. {
  17. var date = (DateTime)obj;
  18. result[""] = date.ToString("yyyy-MM-dd HH:mm:ss");
  19. }
  20. return result;
  21. }
  22. public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
  23. {
  24. throw new NotImplementedException();
  25. }
  26. }