JSON.NET 反序列化问题

发布于 2024-10-18 13:23:25 字数 950 浏览 2 评论 0原文

我一整天都在为下一个 JSON 字符串而苦苦挣扎,

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

我该如何反序列化它?下一个代码(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)

它总是返回空结果。

谢谢!

雷蒙德

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

{
"0":{"link":"afbeeldingenplaatje1.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你不是我要的菜∠ 2024-10-25 13:23:25

json 数据和您的模型不匹配。

尝试这样做:

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

或者将数据输入更改为:

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

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"}
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文