ObjectExtensions.cs 783 B

12345678910111213141516171819202122232425262728
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.Encodings.Web;
  7. using System.Text.Json;
  8. using System.Text.Json.Serialization;
  9. using System.Text.Unicode;
  10. using System.Threading.Tasks;
  11. public static class ObjectExtensions
  12. {
  13. /// <summary>
  14. /// 使用Newtonsoft Json将object转换为Json字符串
  15. /// </summary>
  16. /// <param name="this"></param>
  17. /// <returns></returns>
  18. public static string ToJson(this object @this)
  19. {
  20. JsonSerializerSettings jsonSettings = new JsonSerializerSettings
  21. {
  22. DateFormatString = "yyyy-MM-dd HH:mm:ss",
  23. };
  24. var str = Newtonsoft.Json.JsonConvert.SerializeObject(@this, jsonSettings);
  25. return str;
  26. }
  27. }