Deserializing JSON String to VB.net Object

Viewed 21008

I'm trying to convert a JSON String into an VB.net Object to get easy access to alle the data in the JSON String.

My JSON String looks like this:

{
  "status": "ok",
  "count": 4,
  "data": [
    {
      "clan_id": 500002846,
      "nickname": "Azrael",
      "id": 500429872
    },
    {
      "clan_id": null,
      "nickname": "Azrael0",
      "id": 500913252
    },
    {
      "clan_id": 500028112,
      "nickname": "Azrael0313",
      "id": 504109422
    },
    {
      "clan_id": null,
      "nickname": "Azrael7",
      "id": 501594186
    }
  ]
}

Now I'm trying to deserialize this String into an VB.net Object

My class definitions are:

Public Class Rootobject
    Private _data1 As String

    Public Property status As String
    Public Property count As Integer
    Public Property data() As Datum
End Class

Public Class Datum
    Public Property clan_id As Integer?
    Public Property nickname As String
    Public Property id As Integer
End Class

which Visual Studio 2012 automatically created for my JSON String.

I tried to deserialize with .JSON Deserializer:

Dim Testobject As Rootobject _
= Global.Newtonsoft.Json.JsonConvert.DeserializeObject(Of Rootobject)(JSON_String)

and with JavaScriptSerializer:

Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim Testobject_2 As Rootobject = serializer.Deserialize(Of Rootobject)(JSON_String)

But in both cases I am just able to get access to "status" and "count" but not to the "data" array.

I'm new to Visual Basic, so i read a lot about JSON and Deserializer and other people with this kind of problems, but most solutions are for C# and not for VB.net

Any Ideas what I might did wrong?

2 Answers
Related