开发者

Dictionary is not supported for deserialization of an array

UPDATED:

I have the following code, where I am trying to use returned JSON data, deserialize it, and return 1 part of that data back to the user.

<%@ 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 = val开发者_C百科ue
            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>

I don't understand how to deserialize into the Item class, then how to get the data back out.


Your data is an array, and you're trying to deserialize it into Dictionary. This won't work.

Either change your input data or deserialize it to an array.

You can also declare a class and use it in the deserialization.

C#, sorry:

class Item
{
    public double some_number { get; set; }
    public string some_text { get; set; }
    public string serial_number { get; set; }
}

and deserialize to List(Of Item)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜