Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top