码迷,mamicode.com
首页 > Web开发 > 详细

DataTable转Json

时间:2015-12-28 12:03:13      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
public string DataTableToJson(DataTable dt) { 
            StringBuilder strbuding = new StringBuilder();
            strbuding.Append("[");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strbuding.Append("{");
                for (int j = 0; j < dt.Columns.Count; j++) {
                    strbuding.Append("\"");
                    strbuding.Append(dt.Columns[j].ColumnName);
                    strbuding.Append("\":\"");
                    strbuding.Append(dt.Rows[i][j].ToString());
                    strbuding.Append("\",");
                }
                strbuding.Remove(strbuding.Length - 1, 1);
                strbuding.Append("},");
            }
            strbuding.Remove(strbuding.Length-1,1);
            strbuding.Append("]");
            return strbuding.ToString();
        }
View Code

 

DataTable转Json

标签:

原文地址:http://www.cnblogs.com/myloveblogs/p/5081828.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!