Newtonsoft.Json反序列化 转成Json字符串
2015-08-19 17:21
477 查看
1:需要引用 Newtonsoft.Json.dll
2:命名空间 using Newtonsoft.Json
输出结果
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<DataRow>().Select(u => u[0]), series = Arr.Select(u => new { name = name[u], data = newTable.Rows.Cast<DataRow>().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","data":[{"name":"02:00","y":"10"},{"name":"01:00","y":"21"}]}], "chartOptions":{"title":{"text":""},"xAxis":{"showFirstLabel":true,"showLastLabel":true,"tickmarkPlacement":"on"},"yAxis":{"title":{"enabled":false},"name":"网站数据"},"plotOptions":{"series":{"marker":{"enabled":false}}},"credits":{"text":""}}
}
相关文章推荐
- js回车键事件
- JavaScript
- 学习zepto.js(对象方法)[4]
- js脚本分页代码分享(7种样式)
- javascript 布局 第20节
- 生动详细解释javascript的冒泡和捕获,包懂包会(转)
- javascript字符串
- JavaScript中使用arguments获得函数传参个数实例
- javascript--单例模式
- javascript DOM操作 第19节
- 《JavaScript高级程序设计》读书笔记 2
- JS原型对象通俗"唱法"
- js原生实现FastClick事件
- javascript函数对象模式--纠结的用法
- javascript DOM 节点 第18节
- asp.net中后台c#数组与前台js数组交互
- 关于Jsp页面在ww:iterator 标签里面判断的写法是可以直接写数组里面的变量的
- js的结构类型理解
- JS日期显示格式 yyyy-MM-dd hh:mm:ss
- [rxjs] Creating An Observable with RxJS