送你2个内部函数
Row2JObject:
Dim dr As DataRow = args(0)
Dim jo As JObject = args(1)
For Each dc As DataCol In dr.DataTable.DataCols
If dc.IsString Then
jo(dc.Name) = CStr(dr(dc.Name))
Else If dc.IsBoolean Then
jo(dc.Name) = CBool(dr(dc.Name))
Else If dc.IsNumeric Then
jo(dc.Name) = Val(dr(dc.Name))
Else If dc.IsDate Then
If dr.Isnull(dc.Name) =False Then
jo(dc.Name) = CStr(dr(dc.Name))
Else
jo(dc.Name) = ""
End If
End If
Next
Table2Json:
Dim e As RequestEventArgs = args(0)
Dim dt As DataTable = args(1)
Dim jo As New JObject
Dim ja As New JArray
jo("list") =ja
For i As Integer =0 To (dt.DataRows.Count - 1)
Dim jo2 As new JObject
ja.Add(jo2)
Dim dr As DataRow = dt.DataRows(i)
Functions.Execute("Row2JObject",dr,jo2)
Next
e.WriteString(CompressJson(jo))
'jo就是你要的最终json
[此贴子已经被作者于2020/3/8 14:16:21编辑过]