【发布时间】:2019-05-01 04:44:09
【问题描述】:
如何生成 JSON 数据用于绑定 JQUERY 数据表?
我在 ASP.net Web 服务 (.asmx) 中使用以下代码
<WebMethod()> _
Public Function Getcdata() As String
Dim dt As New DataTable()
Using con As New SqlConnection(IDvar.Constr)
Using cmd As New SqlCommand("Select * from COMPLAINTTYPE", con)
con.Open()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
rows.Add(row)
Next
Context.Response.Write(serializer.Serialize(dt))
con.Close()
cmd.Dispose()
dt.Clear()
End Using
End Using
End Function
但这会返回错误。请检查我哪里错了
我在调用 web 方法时遇到的错误如下:
System.InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
【问题讨论】:
标签: jquery asp.net json vb.net datatable