JsonUtils.cs 667 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json;
  7. namespace cuidian.Common
  8. {
  9. public class JsonUtils
  10. {
  11. /// <summary>
  12. /// 返回格式化的json字符
  13. /// </summary>
  14. /// <param name="obj"></param>
  15. /// <returns></returns>
  16. public static string GetJsonString(object obj)
  17. {
  18. var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
  19. string s = JsonConvert.SerializeObject(obj, Formatting.Indented, jsonSetting);
  20. return s;
  21. }
  22. }
  23. }