質問

i've searched everywhere and cannot find a solution to deserialize the following:

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

my class file looks like this:

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

i'm trying to use JsonConvert.DeserializeObject with no luck at all...

any help would be greatly appreciated.

edit: tried this.

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)

but I'm not sure if its right nor do I know how to use the text. I'm so lost.

役に立ちましたか?

解決

You need to deserialize direcly to a list of your class:

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)

The deserialize should take care of the rest, so long as things match up properly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top