zoukankan      html  css  js  c++  java
  • DataTable 转Json

    public static string CreateJsonParameters(DataTable dt) { /* /**************************************************************************** * Without goingin to the depth of the functioning of this Method, i will try to give an overview * As soon as this method gets a DataTable it starts to convert it into JSON String, * it takes each row and in each row it grabs the cell name and its data. * This kind of JSON is very usefull when developer have to have Column name of the . * Values Can be Access on clien in this way. OBJ.HEAD[0]. * NOTE: One negative point. by this method user will not be able to call any cell by its index. * *************************************************************************/ StringBuilder JsonString = new StringBuilder(); //Exception Handling if (dt != null && dt.Rows.Count > 0) { JsonString.Append("[ "); // JsonString.Append("\"zNodes\":[ "); for (int i = 0; i < dt.Rows.Count; i++) { JsonString.Append("{ "); for (int j = 0; j < dt.Columns.Count; j++) { if (j < dt.Columns.Count - 1) { JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\","); } else if (j == dt.Columns.Count - 1) { JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\""); } } if (i == dt.Rows.Count - 1) { JsonString.Append("} "); } else { JsonString.Append("}, "); } } JsonString.Append("]"); return JsonString.ToString(); } else { return null; } }

    把学习一种技术一直坚持下去。
  • 相关阅读:
    Jenkins修改用户密码及权限
    Selenium知识点小结
    解析图形验证码登录系统
    Pywinauto实现电脑客户端有道云签到领空间
    Python冒泡排序
    LoadRunner12常用函数
    GIT教程笔记
    LoadRunner 关联
    搭建自动化测试框架Python3+Selenium
    SSH免密从A服务器登录进B服务器,重启B服务器的tomcat
  • 原文地址:https://www.cnblogs.com/cxlings/p/2554045.html
Copyright © 2011-2022 走看看