以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求助下 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=152851) |
-- 作者:blackzhu -- 发布时间: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编辑过]
|
-- 作者:有点蓝 -- 发布时间: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 -- 发布时间: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 你的意思写两个属性类? |
-- 作者:有点蓝 -- 发布时间:2020/7/23 16:52:00 -- 本来就是2个类啊,只是其中一个嵌套到另外一个里面。json对象的转换可能无法识别嵌套的类型 |