Json   发布时间:2022-04-22  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Newtonsoft.Json反序列化 转成Json字符串大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

1:需要引用Newtonsoft.Json.dll

2:命名空间using Newtonsoft.Json

            DataTable newTable = new DataTable();
            newTable.columns.Add("Hour");
            newTable.columns.Add("PV");
            newTable.columns.Add("IP",typeof(int));
            newTable.columns["PV"].DataType = typeof(int);//指定类型
            newTable.Rows.Add("01:00","2","21");
            newTable.Rows.Add("02:00","4","10");


            int[] Arr = { 0,1 };
            List<String> list = new List<String>() { "PV","IP" };
            String[] name = { "今日PV","今日IP" };
            var json = new {
                categories = newTable.Rows.Cast<Da@R_218_2301@w>().SELEct(u => u[0]),series = Arr.SELEct(u => new {
                    name = name[u],data = newTable.Rows.Cast<Da@R_218_2301@w>().SELEct(row => new { name = row[0],y = row[list[u]] }),}),chartOptions = new {
                    title = new { text = "" },xAxis = new {
                        showFirstLabel = true,showLastLabel = true,tickmarkPlacement = "on"
                    },yAxis = new {
                        title = new { enabled = false },name = "网站数据"
                    },plotOptions = new { series = new { marker = new { enabled = false } } },credits = new { text = "" }
                }
            };
            String str_ = JsonConvert.serializeObject(json);

输出结果
{
 "categories":["02:00","01:00"],"series":[{"name":"今日PV","data":[{"name":"02:00","y":"4"},{"name":"01:00","y":"2"}]},{"name":"今日IP","y":"10"},"y":"21"}]}],"chartOptions":{"title":{"text":""},"xAxis":{"showFirstLabel":true,"showLastLabel":true,"tickmarkPlacement":"on"},"yAxis":{"title":{"enabled":falsE},"name":"网站数据"},"plotOptions":{"series":{"marker":{"enabled":falsE}}},"credits":{"text":""}}
}

大佬总结

以上是大佬教程为你收集整理的Newtonsoft.Json反序列化 转成Json字符串全部内容,希望文章能够帮你解决Newtonsoft.Json反序列化 转成Json字符串所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。