c#如何将datatable转化成如下json格式
{"code":0,"msg":"","count":2,"data":[{"id":10000,"username":"user-0","sex":"女","city"...
{"code":0,"msg":"","count":2,"data":[{"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"签名-0","experience":255,"logins":24,"wealth":82830700,"classify":"作家","score":57},{"id":10001,"username":"user-1","sex":"男","city":"城市-1","sign":"签名-1","experience":884,"logins":58,"wealth":64928690,"classify":"词人","score":27}]}其中data里面的值为datatable里面的值,count为两条数据
展开
1个回答
展开全部
第一步,引用Newtonsoft.Json包。
第二步,你的datatable是绑定了一个List<>对像吧,那这样写就好了。
string json = JsonConvert.SerializeObject(new {code=0,msg="",count=2, data = lists });
基本上就是这样啦,希望采纳。
第二步,你的datatable是绑定了一个List<>对像吧,那这样写就好了。
string json = JsonConvert.SerializeObject(new {code=0,msg="",count=2, data = lists });
基本上就是这样啦,希望采纳。
追问
为什么返回来的数据都带反斜杠那"{\"code\":0,\"msg\":\"\",\"count\":2,\"data\":[{\"id\":\"12\",\
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询