以下的代码是将datatable转成json的方法
我想再将json转回成原本的datatable请问要如何现呢? 感谢
Public Function DataTableToJson(ByVal dt As DataTable) As String
Dim jsonBuilder As StringBuilder = New StringBuilder()
For i As Integer = 0 To dt.Rows.Count - 1
jsonBuilder.Append("{")
For j As Integer = 0 To dt.Columns.Count - 1
jsonBuilder.Append("""")
jsonBuilder.Append(dt.Columns(j).ColumnName)
jsonBuilder.Append(""":""")
jsonBuilder.Append(dt.Rows(i)(j).ToString())
jsonBuilder.Append(""",")
Next
If dt.Columns.Count > 0 Then
jsonBuilder.Remove(jsonBuilder.Length - 1, 1)
End If
jsonBuilder.Append("},")
Next
If dt.Rows.Count > 0 Then
jsonBuilder.Remove(jsonBuilder.Length - 1, 1)
End If
Return jsonBuilder.ToString()
End Function