zoukankan      html  css  js  c++  java
  • DataTable 的 JSON 序列化

        public string CreateJsonParameters(DataTable dt)
        {
            StringBuilder JsonString = new StringBuilder();
            if (dt != null && dt.Rows.Count > 0)
            {
                JsonString.Append("[ ");
                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().Trim();
            }
            else
            {
                return null;
            }
        }
  • 相关阅读:
    linux 共享内存 信号量 同步
    进程间通信 共享内存
    linux 多进程绑定问题
    C 语言调用python 脚本函数
    C 语言 和 python 调用 .so 文件
    好好学习
    three.js
    AMD、CMD、UMD 模块的写法
    webpack查缺补漏
    什么是 Web 服务器(server)
  • 原文地址:https://www.cnblogs.com/systemxgl/p/1560364.html
Copyright © 2011-2022 走看看