zoukankan      html  css  js  c++  java
  • 后台拼接tree的json格式

    public static string GetChannelTreeNodeJson()
            {
                Database db = DatabaseFactory.CreateDatabase();
                string sql = @"SELECT PageId
                              ,pageName
                              ,cregex
                              ,parentId
                              ,dregex FROM LogFile_Page ";
                DbCommand mycmd = db.GetSqlStringCommand(sql);
                DataSet ds = db.ExecuteDataSet(mycmd);
                System.Text.StringBuilder s = new System.Text.StringBuilder();
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    s.Append(GetChildNodes(dt, "00"));
                    s = s.Remove(s.Length - 2, 2);
    
                }
                return s.ToString();
            }
            public static string GetChildNodes(DataTable dt, string parentid)
            {
                StringBuilder stringbuilder = new StringBuilder();
                DataRow[] CRow = dt.Select("parentId=" + parentid);
                if (CRow.Length > 0)
                {
                    stringbuilder.Append("[");
                    for (int i = 0; i < CRow.Length; i++)
                    {
                        string chidstring = GetChildNodes(dt, CRow[i]["PageId"].ToString());
                        if (!string.IsNullOrEmpty(chidstring))
                        {
                            stringbuilder.Append("{ \"id\":\"" + CRow[i]["PageId"].ToString() + "\",\"text\":\"" + CRow[i]["pageName"].ToString() + "\",\"state\":\"closed\",\"children\":");
                            stringbuilder.Append(chidstring);
                        }
                        else
                        {
                            stringbuilder.Append("{\"id\":\"" + CRow[i]["PageId"].ToString() + "\",\"text\":\"" + CRow[i]["pageName"].ToString() + "\"},");
                        }
                    }
                    stringbuilder.Replace(',', ' ', stringbuilder.Length - 1, 1);
                    stringbuilder.Append("]},");
                }
                return stringbuilder.ToString();
            }
  • 相关阅读:
    #define中的特殊符号
    c++ windows下计时
    c++内存池
    u3d 场景资源打包
    Unity3d 动态加载材质方法
    Unity3D Shader基础教程
    Unity3D Shader入门指南(一)
    Unreal发展史
    阴影锥(shadow volume)原理与展望
    软硬RAID 和 不常见的RAID
  • 原文地址:https://www.cnblogs.com/chzbgb/p/6801431.html
Copyright © 2011-2022 走看看