C# datatble 转json数组

#region 将datatable转换成json数组
                System.Collections.ArrayList dic = new System.Collections.ArrayList();
                DataTable dt = null;
                DataTable dtNew = null;
                DataRow[] drArr = null;
                if (dataSet.Tables.Count > 0)
                {
                    dt = dataSet.Tables[0];
                    drArr = dt.Select("");
                    //按条件查询,只能查询当前页,查询所有数据sql语句已经写了
                    dtNew = dt.Clone();
                    for (int i = 0; i < drArr.Length; i++)
                    {
                        dtNew.ImportRow(drArr[i]);
                    }
                }
                foreach (DataRow dr in dtNew.Rows)
                {
                    System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
                    foreach (DataColumn dc in dt.Columns)
                    {
                        //drow.Add($"{dc.ColumnName}", dr[dc.ColumnName]);
                        drow.Add(dc.ColumnName, StampToDateTime(Convert.ToString(dr[dc.ColumnName])));
                    }
                    dic.Add(drow);

                }

                #endregion

 

上一篇:Collection和Collections的区别及二分查找法


下一篇:Java-Collections工具类