在页面内容显示时,有时需要用到json格式。但数据库内容的显示,需要将数据库中获取的格式转为json:

using Newtonsoft.Json;
public
static string ToJson(object obj) { return JsonConvert.SerializeObject(obj); } public static string ToJson(object obj, int records) { string json = ToJson(obj); return @"{""total"":" + records.ToString() + @",""rows"":" + json + "}"; }

第一段代码是直接将object格式转为json格式;第二段是在转json的基础上,加上total总数。

上述代码一般定义在.Common项目中的JsonHelper中。

相关文章:

  • 2021-08-06
  • 2021-07-23
  • 2022-03-09
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2021-05-31
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案