以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  DataTable 转json  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=175684)

--  作者:chen_sheng
--  发布时间:2022/3/15 14:16:00
--  DataTable 转json
和第三方系统对接接口 需要抛转数据给第三方  如何把DataTables("表A")的所有数据转为json

Dim dt As DataTable = DataTables("表A")
dt.Find("第一列 Is Not Null")
Dim jo As New JObject
Dim ja As New JArray
jo("dh") = "001"
jo("zt") = "1"
jo("sj") =  ja \'
ja.Add(New JObject) 
For Each dr As DataRow In dt.DataRows
    \'给数组添加两个对象成员
    ja(0)("name") = dr("第一列").ToString
    ja(0)("sl") = dr("第二列").ToString
    
Next
Output.Show(jo.ToString)

--  作者:有点蓝
--  发布时间:2022/3/15 14:32:00
--  
Dim jo As New JObject
Dim ja As New JArray
jo("dh") = "001"
jo("zt") = "1"
jo("sj") =  ja \'

Dim jo2 As JObject
For Each dr As DataRow In dt.DataRows
jo2= new JObject
    \'给数组添加两个对象成员
    jo2("name") = dr("第一列").ToString
    jo2("sl") = dr("第二列").ToString
  ja.Add(jo2  
Next