开发者

JSON.NET Deserialize problem

开发者 https://www.devze.com 2023-02-12 15:19 出处:网络
I\'m strugling the whole day with the next JSON string { \"0\":{\"link\":\"afbee开发者_运维技巧ldingenplaatje1.jpg\"},

I'm strugling the whole day with the next JSON string

{
"0":{"link":"afbee开发者_运维技巧ldingenplaatje1.jpg"},
"1":{"link":"afbeeldingenplaatje2.jpg"},
"2":{"link":"afbeeldingenplaatje3.jpg"}
}

How can i deserialize this? What's wrong with the next code (vb.net)

Public Class DataString
    Private m_link As String
    Public Property link() As String
        Get
            Return m_link
        End Get
        Set(ByVal value As String)
            m_link = value
        End Set
    End Property
End Class

Public Class DataToArray
    Private a_Data As Dictionary(Of Integer, DataString)
    Public Property DataTo() As Dictionary(Of Integer, DataString)
        Get
            Return a_Data
        End Get
        Set(ByVal value As Dictionary(Of Integer, DataString))
            a_Data = value
        End Set
    End Property

Dim template As DataToArray = JsonConvert.DeserializeObject(Of DataToArray)(sData)

it returns always an empty result.

Thanks!

Raymond


The json data and your model does not match.

Try doing this instead:

Dim template As DataToArray = JsonConvert.DeserializeObject(Of Dictionary(Of Integer, DataString))(sData)

Or change the data input to:

{
    DataTo: {
        "0":{"link":"afbeeldingenplaatje1.jpg"},
        "1":{"link":"afbeeldingenplaatje2.jpg"},
        "2":{"link":"afbeeldingenplaatje3.jpg"}
    }
}
0

精彩评论

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