vb.net datatable Serialize to json

后端 未结 2 654
死守一世寂寞
死守一世寂寞 2021-01-05 02:22

I have this kind of table:

\"\"

I need to get this JSON (of course order could be any, structure/tree

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 02:56

    The 'Oh-no you didn't' version:

    Public Function GetJson(ByVal dt As DataTable) As String
        Return New JavaScriptSerializer().Serialize(From dr As DataRow In dt.Rows Select dt.Columns.Cast(Of DataColumn)().ToDictionary(Function(col) col.ColumnName, Function(col) dr(col)))
    End Function
    

提交回复
热议问题