更新:
我有以下代码,我尝试使用returned
JSON数据,对其进行反序列化,并将该数据的一部分返回给用户。
<%@ Page Language="VB" Debug="True" EnableViewState="false" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<script runat="server">
Class Item
Public Property some_number() As Double
Get
Return m_some_number
End Get
Set(ByVal value As Double)
m_some_number = value
End Set
End Property
Private m_some_number As Double
Public Property some_text() As String
Get
Return m_some_text
End Get
Set(ByVal value As String)
m_some_text = value
End Set
End Property
Private m_some_text As String
Public Property serial_number() As String
Get
Return m_serial_number
End Get
Set(ByVal value As String)
m_serial_number = value
End Set
End Property
Private m_serial_number As String
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Clear()
Response.Write(set_profiles())
Response.End()
End Sub
Function set_profiles() As String
' get returned json data
Dim strChanged As String = CType(Request.Form("strChanged"), String)
' deserialize returned data
Dim jss = New JavaScriptSerializer()
' assuming i need to change this line now?
Dim dict As Dictionary = jss.Deserialize(List(Of Item))(strChanged)
Return dict("some_number")
End Function
</script>
我不明白如何反序列化到Item
类,然后如何恢复数据。
答案 0 :(得分:2)
您的数据是一个数组,并且您正在尝试将其反序列化为Dictionary。这不起作用。
更改输入数据或将其反序列化为数组。
您也可以声明一个类并在反序列化中使用它。
C#,抱歉:
class Item
{
public double some_number { get; set; }
public string some_text { get; set; }
public string serial_number { get; set; }
}
并反序列化为List(Of Item)