以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  json格式数据生成  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=169660)

--  作者:chen_sheng
--  发布时间:2021/6/24 20:53:00
--  json格式数据生成
如何用sql查询到的数据生成需求的json格式
查询内容:
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "S ELECT level,appType,desc  FROM 明细"
cmd.CommandTimeOut = 50000
Dim dt As DataTable = cmd.ExecuteReader()

需求数据处理的格式
{
"data": {
"responseData": {
"data": [
{
"level": "A",
"appType": "小贷业务",
"desc": "风险小,借款多"
},
{
"level": "B",
"appType": "增值业务",
"desc": "风险小,借款多"
}
],
"totals": 2
},
"columnData": [
{
"key": "level",
"text": "风险级别"
},
{
"key": "appType",
"text": "业务类型"
},
{
"key": "desc",
"text": "风险描述"
}
]
}
}
[此贴子已经被作者于2021/6/24 20:53:47编辑过]

--  作者:有点蓝
--  发布时间:2021/6/24 21:08:00
--  
参考:http://www.foxtable.com/mobilehelp/topics/0167.htm
--  作者:chen_sheng
--  发布时间:2021/6/24 21:43:00
--  
看了半天  实在是鼓捣不出来
\'Dim jo As New JObject \'用于生成和解析JSON数据
\'    Dim jo1 As New JObject \'用于生成和解析JSON数据
\'
\'jo("data") = jo1
\'   Dim ja As New JArray \'定义数组
\'      jo1("responseData") = ja
\'        Dim jo2 As New JObject
\'           ja("data") =  jo2 
\'
\'             Dim ja1 As New JArray \'定义数组
\'         For Each dr As DataRow in dt.DataRows     
\'\'         ja1("level") = dr("level").ToString \'转json对象,要tostring
\'         ja1("appType") = dr("appType").ToString \'转json对象,要tostring
\'         ja1("desc") = dr("desc").ToString \'转json对象,要tostring
\' jo2.Add(ja1)
\'         Next
\' Dim ja2 As New JArray
\' jo1("columnData") = ja2
\'     Dim ja21 As New JArray
\' ja21(0)("key") = "level"
\' ja21(0)("text") = "风险级别"
\' ja21(1)("key") = "appType"
\' ja21(1)("text") = "业务类型"
\' ja21(2)("key") = "desc"
\' ja21(2)("text") = "风险描述"
\'
\'    e.WriteString(jo.ToString)
[此贴子已经被作者于2021/6/24 21:47:48编辑过]

--  作者:有点蓝
--  发布时间:2021/6/24 21:58:00
--  
Dim jo As New JObject
Dim jo1 As New JObject
jo1("responseData") = New JObject
jo("data") = jo1
Dim ja As New JArray
Dim jo2 As JObject
For Each dr As DataRow in dt.DataRows
jo2 = new JObject
jo2("type1") = dr("派工时间").ToString
……
ja.add(jo2)
next
jo1("responseData")("data") = ja
jo1("responseData")("totals") = dt.DataRows.count
Dim ja2 As New JArray
jo1("columnData") = ja2
jo2 = new JObject
jo2("type1") = "type1"
……
ja2.add(jo2)
output.show(jo.ToString)