zoukankan      html  css  js  c++  java
  • .NET DataTable转化为json格式

    标准的json用“分隔,不用' 

    public static string DataSetToJson(DataTable dt)

       {
           string json = string.Empty;
           try
           {
               if (dt==null||dt.Rows.Count == 0)
               {
                   return "";
               }
               json = "{";
               json += "'table" + 1 + "':[";
               for (int i = 0; i < dt.Rows.Count; i++)
               {
                   json += "{";
                   for (int j = 0; j < dt.Columns.Count; j++)
                   {
                       json += "'" + dt.Columns[j].ColumnName + "':'" + dt.Rows[i][j].ToString() + "'";
                       if (j != dt.Columns.Count - 1)
                       {
                           json += ",";
                       }
                   }
                   json += "}";
                   if (i != dt.Rows.Count - 1)
                   {
                       json += ",";
                   }
               }
               json += "]";
               json += "}";
           }
           catch (Exception ex)
           {

               throw new Exception(ex.Message);
           }
           return json;
       }

  • 相关阅读:
    Linux定时任务
    linux文件权限
    grep awk sed 三剑客
    用户管理
    find查找inode号删除文件
    find 查找文件或目录 及du命令
    11、注册新用户
    10、密码扩展,使用Flask-Login认证用户
    9、大型程序的结构
    8、目前flask程序结构
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3231074.html
Copyright © 2011-2022 走看看