我整天都在使用下一个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)
它总是返回一个空结果。
谢谢!
雷蒙德
答案 0 :(得分:1)
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"}
}
}