查看Layui Table所需Json格式

{"code":0,"msg":"","count":1000,"data":[{"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"签名-0","experience":255,"logins":24,"wealth":82830700,"classify":"作家","score":57}]}

解析Json数据

Json解析网站 https://www.json.cn/

Json转实体类

Json2Entity https://www.sojson.com/json2entity.html

将Json数据粘贴即可

public class Data
{
    /// <summary>
    /// 
    /// </summary>
    public int id { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public string username { get; set; }
    /// <summary>
    /// 女
    /// </summary>
    public string sex { get; set; }
    /// <summary>
    /// 城市-0
    /// </summary>
    public string city { get; set; }
    /// <summary>
    /// 签名-0
    /// </summary>
    public string sign { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public int experience { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public int logins { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public int wealth { get; set; }
    /// <summary>
    /// 作家
    /// </summary>
    public string classify { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public int score { get; set; }
}

public class Root
{
    /// <summary>
    /// 
    /// </summary>
    public int code { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public string msg { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public int count { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public List<Data> data { get; set; }
}

引用NuGet中的Json.Net

List To Json

注意数据拼接


        jsonDatas = jsonDatas.Where(a => a.RowID >= fpageindex && a.RowID <= epageindex).ToList();

            ManpowerMODEL.UserJsonEdit.JsonRoot jsonRoot = new ManpowerMODEL.UserJsonEdit.JsonRoot()
            {
                code = 0,
                msg = "",
                count = dt.Rows.Count,
                data = jsonDatas
            };
            //list转Json
            string StrJson = JsonConvert.SerializeObject(jsonRoot);

返回数据

最后修改:2020 年 12 月 14 日 10 : 13 PM
如果觉得我的文章对你有用,请随意赞赏