0
点赞
收藏
分享

微信扫一扫

一段处理json的C#代码

泠之屋 2022-08-15 阅读 84


服务器端:

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public ActionResult GetGatherData()
{
IList<M_Gather> list = gatherpolygonService.GetAll();

JArray jarr = new JArray();
foreach (var g in list)
{
jarr.Add(new JObject()
{
new JProperty("ID",g.GATHERID),
new JProperty("POINTNAME",g.POINTNAME),
new JProperty("DEVICEID",g.DEVICEID),
});
}
JObject jobj = new JObject()
{
new JProperty("totalCount",getall.Count()),
new JProperty("topics",jarr)
};

return Content(JsonConvert.SerializeObject(jobj), "application/json");
}

得到的json如下:

{
totalCount:10,
topics:[
{ID:"","POINTNAME":"","DEVICEID":""},...
]
}

举报

相关推荐

0 条评论