Teddy Higgins Teddy Higgins - 2 months ago 9
Vb.net Question

json key with array of values - how to parse

This is the json data I am trying to parse. (I did trim the imagedata down for example purposes)

{"imageData":["SUkqAORlAACGniG0JCHeSTV9icwWxF+N9AwzcsTDlLu+PeYCgeZXAP//","sfsdfsdyfhh2h43h8ysdfsdnvjknjfdsfdsf"]}


Any idea on how to parse it into a strongly typed class in .NET?

I am using the newtonsoft.json

I tried the following

Public Class DAFGImages
Public imageData As List(Of String)
End Class

Dim DAFGImages As List(Of DAFGImages) = Newtonsoft.Json.JsonConvert.DeserializeObject(json, GetType(List(Of DAFGImages)))

Answer

Your class already contains a List of string, so you dont need a list of DAFGImages too. I would change the class member to a property:

Public Class DAFGImages
    Public Property imageData As List(Of String)
End Class

Then:

Dim jstr = ... from wherever
Dim myImgs = Newtonsoft.Json.JsonConvert.DeserializeObject(Of DAFGImages)(jstr)

myImgs.ImageData will contain the 2 elements.

Comments