在VB12中反序列化JSON文本

时间:2013-12-19 00:02:46

标签: json vb.net json-deserialization

我到处搜索,无法找到解决方案来反序列化以下内容:

[
   {
     "picture":"URL_TO_PICTURE",
     "link":"URL_TO_SITE"
   },
   {
     "picture":"URL_TO_PICTURE",
     "link":"URL_TO_SITE"
   },
   {
     "picture":"URL_TO_PICTURE",
     "link":"URL_TO_SITE"
   }
]

我的类文件如下所示:

Public Class BonusItems
    Public Property picture As String
    Public Property link As String
End Class

我正试图使用​​JsonConvert.DeserializeObject而根本没有运气......

任何帮助将不胜感激。

编辑:试过这个。

Dim json As String = "[ {""picture"":""URL_PIC_1"", ""link"":""URL_LINK_1""}, {""picture"":""URL_PIC_1"", ""link"":""URL_LINK_1""} ]"
Dim Items As List(Of Dictionary(Of String, String)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, String)))(json)

但我不确定它是否正确,也不知道如何使用该文本。我迷路了。

1 个答案:

答案 0 :(得分:1)

您需要直接反序列化到您的班级列表:

Dim json As String = "[ {""picture"":""URL_PIC_1"", ""link"":""URL_LINK_1""}, {""picture"":""URL_PIC_1"", ""link"":""URL_LINK_1""} ]"

Dim items As List(Of BonusItems) = JsonConvert.DeserializeObject(Of List(Of BonusItems))(json)

反序列化应该照顾其余部分,只要事情正确匹配。