Foxtable(狐表)用户栏目专家坐堂 → 求助下


  共有2985人关注过本帖树形打印复制链接

主题:求助下

帅哥哟,离线,有人找我吗?
blackzhu
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:狐仙 帖子:9879 积分:57634 威望:0 精华:15 注册:2008/9/1 9:45:00
求助下  发帖心情 Post By:2020/7/23 16:32:00 [只看该作者]

我写了一个属性类

Public Class GetMenuModels
    Public Property title As String
    Public Property icon As String
    Public Property Spread As String
    Public Property children As List(Of Submenu)


    Public Class Submenu
        Public Property title As String
        Public Property icon As String
        Public Property href As String  
    End Class
End Class




但是函数的最下面遍历不到数据

 Dim dt As DataTable = SqlHelper.MyExecuteReader(SqlText)
        Dim js As JavaScriptSerializer = New JavaScriptSerializer()
        Dim DMenuInfo As New List(Of GetMenuModels)
        Dim outinfo As GetMenuModels = New GetMenuModels()
        Dim Arys As List(Of String())
        Arys = dt.GetValues("nav|lgicon|spread", "", "[no]")
        For Each Ary As String() In Arys
            '这边可以获取数据
            outinfo.title = Ary(0).ToString()
            outinfo.icon = Ary(1).ToString()
            outinfo.Spread = Ary(2).ToString()
            Dim item As New GetMenuModels.Submenu
            Dim Customers As List(Of String())
            Customers = dt.GetValues("navigation|smicon|Url", "nav='" & Ary(0).ToString() & "'", "[no]")
            For Each Customer As String() In Customers
                '这边可以获取数据
                item.title = Customer(0).ToString()
                item.icon = Customer(1).ToString()
                item.href = Customer(2).ToString()
            Next
            outinfo.children.Add(item)
        Next
        DMenuInfo.Add(outinfo)
      '  Dim json As String = js.Serialize(DMenuInfo)
      For each str As GetMenuModels In DMenuInfo  '这边遍历不到数据
        Output.Show(str.ToString)
            next
       ' Return json

是不是我哪边写错代码了?
[此贴子已经被作者于2020/7/23 16:33:08编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/7/23 16:42:00 [只看该作者]

改为不嵌套用法

Public Class GetMenuModels
    Public Property title As String
    Public Property icon As String
    Public Property Spread As String
    Public Property children As List(Of Submenu)
End Class

    Public Class Submenu
        Public Property title As String
        Public Property icon As String
        Public Property href As String  
    End Class

 回到顶部
帅哥哟,离线,有人找我吗?
blackzhu
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:狐仙 帖子:9879 积分:57634 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2020/7/23 16:45:00 [只看该作者]

以下是引用有点蓝在2020/7/23 16:42:00的发言:
改为不嵌套用法

Public Class GetMenuModels
    Public Property title As String
    Public Property icon As String
    Public Property Spread As String
    Public Property children As List(Of Submenu)
End Class

    Public Class Submenu
        Public Property title As String
        Public Property icon As String
        Public Property href As String  
    End Class

你的意思写两个属性类?


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/7/23 16:52:00 [只看该作者]

本来就是2个类啊,只是其中一个嵌套到另外一个里面。json对象的转换可能无法识别嵌套的类型

 回到顶部