Teddy Higgins Teddy Higgins - 1 year ago 74
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)


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 Source

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


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

myImgs.ImageData will contain the 2 elements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download