VB.NET中如何将Datatable转换为Json格式数据
需要引入
Imports System.Web.Script.Serialization
Imports System.Collections.Generic
Public Function Dtb2Json(ByVal dtb As DataTable) As String
Dim jss As JavaScriptSerializer = New JavaScriptSerializer
Dim dic As ArrayList = New ArrayList()
For Each item As DataRow In dtb.Rows
Dim drow As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
For Each col As DataColumn In dtb.Columns
drow.Add(col.ColumnName, item.Item(col.ColumnName))
Next
dic.Add(drow)
Next
Return jss.Serialize(dic)
End Function