如何转化为
[
{"text": "业务统计报表", "cls": "folder","expanded": true,"children": 
[
{"text": "销售报表","id":"2","leaf": true},
{"text": "销售开票资料","id":"3","leaf": true}
]
    }。
]说明一下:Code是分级编码,Level代表级别,Parent是代表该级别的上一级编码,leaf如果是true就是代表是末级

解决方案 »

  1.   

    数据库中的datatable格式如下:
    id    Code      Name              Level    Parent   leaf      cls           url
    1 1          业务统计报表 1      NULL    NULL folder NULL
    2 11         销售报表         2      1            True  NULL NULL
    3 12         销售开票资料 2      1            True   NULL  NULL
      

  2.   

    c#我都找不到有通用的类,只有java,都看不懂
      

  3.   

    这个网上的资料很多啊,要善于使用搜索引擎啊,
    http://www.csharpwin.com/csharpspace/10824r8122.shtml
      

  4.   

    using System.Net.Json;JsonObjectCollection collect = null;
    JsonObjectCollection total = null;
    JsonArrayCollection array = null;private string ParseDataTableToJsonString(DataTable dt)
        {
            total = new JsonObjectCollection();
            array = new JsonArrayCollection();
            array.Name = "detail";
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                collect = new JsonObjectCollection();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    collect.Add(new JsonStringValue(dt.Columns[j].ToString(),dt.Rows[i][j].ToString()));
                }
                array.Add(collect);
            }
            total.Add(array);
            return total.ToString();
        }個人寫的,希望對lz有幫助。
      

  5.   

    谢谢楼上,但是不是我想要的,希望大家看清楚转换成json后的结构和原本的数据库结构,不单单是datatable转化成json这么简单啊
    数据库中的datatable格式如下:
    id Code Name Level Parent leaf cls url
    1 1 业务统计报表 1 NULL NULL folder NULL
    2 11 销售报表 2 1 True NULL NULL
    3 12 销售开票资料 2 1 True NULL NULL
    如何转化为
    [
    { "text ":   "业务统计报表 ",   "cls ":   "folder ", "expanded ":   true, "children ":  
    [
    { "text ":   "销售报表 ", "id ": "2 ", "leaf ":   true},
    { "text ":   "销售开票资料 ", "id ": "3 ", "leaf ":   true}
    ]

            }。
    ]说明一下:Code是分级编码,Level代表级别,Parent是代表该级别的上一级编码,leaf如果是true就是代表是末级
    关键是红色字体
      

  6.   

    json只是一种转化的方式,你的要求是
    先把datatable转化成一个可序列化类,该类就是要用来json的东东你去网上找个菜单构造的例子就知道怎么利用组合模式构造这个类了
      

  7.   

    这个我都知道,就是不知道怎么构造children