以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  这个json 需要如何修改?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=126032)

--  作者:blackzhu
--  发布时间:2018/10/12 14:00:00
--  这个json 需要如何修改?
Dim dt As DataTable = Nothing
Dim foxdt As DataTable = Nothing
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Se           lect 主菜单 AS menuname,icon from 系统授权"
dt = cmd.ExecuteReader
Dim ja As New JArray
Dim i As Integer
Dim Arys As List(Of String())
Arys = dt.GetValues("menuname|icon") \'列名用符号|分割
For Each Ary As String() In Arys
    ja.Add(New JObject)
    ja(i)("menuid") = i.Tostring
    ja(i)("menuname") = Ary(0).ToString
    ja(i)("icon") = Ary(1).ToString
    i = i + 1
Next
Dim jo As New JObject
jo("menus") = ja
cmd.CommandText = "Sel           ect 模块名称 AS menuname,icon,url from 系统授权"
foxdt = cmd.ExecuteReader
Arys = foxdt.GetValues("menuname|icon|url") \'列名用符号|分割
For Each Ary As String() In Arys
    ja.Add(New JObject)
    ja(i)("menuid") = i.Tostring
    ja(i)("menuname") = Ary(0).ToString
    ja(i)("icon") = Ary(1).ToString
    ja(i)("url") = Ary(2).ToString
    i = i + 1
Next
jo("menus") = ja

Dim json As String = jo.ToString
\'\'e.WriteString(json)
MsgBox(json)


我需要的格式是:


"menus": [
{
"menuid": "1", "icon": "icon-sys", "menuname": "业务管理",
"menus": [
{ "menuid": "12", "menuname": "意向客户登记", "icon": "icon-add", "url": "layout-1.html" },
{ "menuid": "13", "menuname": "分诊接待", "icon": "icon-users", "url": "layout-2.html" },
{ "menuid": "14", "menuname": "现场咨询", "icon": "icon-role", "url": "layout-3.html" },
{ "menuid": "15", "menuname": "权限设置", "icon": "icon-set", "url": "demo.html" },
{ "menuid": "16", "menuname": "系统日志", "icon": "icon-log", "url": "demo1.html" }
]
}
]

--  作者:有点甜
--  发布时间:2018/10/12 14:35:00
--  

参考

 

Dim jo As New JObject
Dim ja As New JArray
jo("menus") = ja
ja.Add(New JObject) \'给数组添加两个对象成员
ja(0)("menuid") = "1"
ja(0)("icon") = "icon-sys"
Dim jja As new JArray
ja(0)("menus") = jja
jja.Add(new JObject)
jja(0)("menuid") = "12"
jja(0)("menuname") = "意向客户登记"
jja.Add(new JObject)
jja(1)("menuid") = "13"
jja(1)("menuname") = "分诊接待"
Output.Show(jo.ToString)

 


--  作者:blackzhu
--  发布时间:2018/10/12 14:45:00
--  
我研究下
--  作者:blackzhu
--  发布时间:2018/10/12 15:12:00
--  
Dim dt As DataTable = Nothing
Dim foxdt As DataTable = Nothing
Dim cmd As New SQLCommand
cmd.C
Dim Arys As List(Of String())
cmd.CommandText = "Sele      ct * from 系统授权"
dt = cmd.ExecuteReader
Arys = dt.GetValues("主菜单|模块名称|icon|url") \'列名用符号|分割
Dim jo As New JObject
Dim ja As New JArray
jo("menus") = ja
Dim i As Integer
For Each Ary As String() In Arys
i = i + 1
    ja.Add(New JObject) \'给数组添加两个对象成员
    ja(i)("menuid") = i.Tostring
    ja(i)("menuname") = Ary(0).ToString
    ja(i)("icon") = Ary(2).ToString
    Dim jja As new JArray
    ja(i)("menus") = jja
    jja.Add(New JObject)
    jja(i)("menuid") = i.Tostring
    jja(i)("menuname") = Ary(1).ToString
    jja(i)("icon") = Ary(2).ToString
    jja(i)("url") = Ary(3).ToString
Next

问题出在什么地方? 貌似i 有问题

--  作者:有点甜
--  发布时间:2018/10/12 15:18:00
--  

1、ja和jja不能写在同一个循环,一个是父节点一个是子节点。

 

2、具体的表格数据发出来测试。


--  作者:blackzhu
--  发布时间:2018/10/12 15:24:00
--  

我真不明白现在为啥传个东西那么麻烦!
[此贴子已经被作者于2018/10/12 15:41:44编辑过]

--  作者:blackzhu
--  发布时间:2018/10/12 15:45:00
--  

不对呀 换了三个浏览器,上传到96%就报服务器错误


--  作者:有点甜
--  发布时间:2018/10/12 15:52:00
--  

上传才能测试,不然看懂

 

Dim jo As New JObject
Dim ja As New JArray
jo("menus") = ja
\'这里写一个循环
ja.Add(New JObject) \'给数组添加两个对象成员
ja(0)("menuid") = "1"
ja(0)("icon") = "icon-sys"
Dim jja As new JArray
ja(0)("menus") = jja

\'这里写一个子循环
jja.Add(new JObject)
jja(0)("menuid") = "12"
jja(0)("menuname") = "意向客户登记"
jja.Add(new JObject)
jja(1)("menuid") = "13"
jja(1)("menuname") = "分诊接待"

Output.Show(jo.ToString)


--  作者:blackzhu
--  发布时间:2018/10/12 15:57:00
--  
上来了

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:json.foxdb



--  作者:blackzhu
--  发布时间:2018/10/12 16:18:00
--  
帮我看下