문제

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