• 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;
            }
        }
  • 相关阅读:
    正则,ant antd from验证input框只能输入数字
    React 实现简易轮播图
    Moment.js ,JavaScript 日期处理类库
    JavaScript中准确的判断数据类型--四种方法
    介绍:一款可以描绘圆圈进度条的jQuery插件(可用作统计图)
    给网页增加水印的方法,react
    IntelliJ IDEA创建web项目及异常问题解决
    CSS 代码是什么?(转)
    JSP入门:介绍什么是JSP和Servlet(转)
    INTELLIJ IDEA集成CHECKSTYLE(转)
  • 原文地址:https://www.cnblogs.com/systemxgl/p/1560364.html
Copyright © 2020-2023  润新知