1

I installed JSON.Net through NuGet and now I want to parse a json array with objects to a list of objects in VB.NET. I have no idea where to begin.

My JSON array:

[
  {
    "servername": "US - New Jersey",
    "ovpnlocation": "servers/newjersey.ovpn"
  },
  {
    "servername": "The Netherlands",
    "ovpnlocation": "servers/nl.ovpn"
  },
  {
    "servername": "Belgium",
    "ovpnlocation": "servers/belgium.ovpn"
  }
]

I have a list of objects that I want to fill:

Dim ServerList As New List(Of ServerLocation)

And my ServerLocation class contains this:

Public Property ServerName As String
Public Property OVPNLocation As String

1 Answer 1

4

Using JSON.Net something like this should work, json being a string holding the JSON you listed above:

Dim ServerList As List(Of ServerLocation) = JsonConvert.DeserializeObject(Of List(Of ServerLocation))(json)
Sign up to request clarification or add additional context in comments.

1 Comment

Combined this with "<JsonProperty("servername")>" & "<JsonProperty("ovpnlocation")>" in my class and it works flawlessly. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.