0

I have this nested structure

enter image description here

and want to parse it into classes. I have this code to get the json file and to deserialize it

 Public Function getData(ByVal _token As String, ByVal _identifier As String) As Results_FullData
    Dim client = New RestClient(_baseURI)
    Dim request = New RestRequest("/datasource/{id}/data", Method.GET)
    request.AddParameter("id", _identifier)
    request.AddUrlSegment("id", _identifier)
    request.AddHeader("Authorization", "Bearer " + _token)
    request.AddHeader("environment", _environment)
    Dim jstr = client.Execute(request).Content
    Dim allData As Results_FullData = JsonConvert.DeserializeObject(Of Results_FullData)(jstr)

    Return allDATA

End Function

And build this class structure

Public Class Results_FullData
    Public Property results As List(Of DSContent)
End Class

Public Class DSContent
    Public Property userRunId As Long
    Public Property metaColumnValues As List(Of String)
    Public Property dataColumnValues As List(Of String)
End Class

But running the code the object datasourceInfo is empty and I do not know why. I thought I could just adopt the solution of this answer but it does not work. I guess the List(Of String) part is wrong. The problem mibht be that the length of metaColumnValues und dataColumnValues differs within each object {}. The idea is to get it into a string and seperate it later, since the values are , seperated within the object

Anyone who can help me here?

Edit: Dataexample:

{"result":[{"userRunId":"xxxxxxx","metaColumnValues":["9006409","20073"],"dataColumnValues":["","superior"]},{"userRunId":"xxxxxxx","metaColumnValues":["2345","235","1"],"dataColumnValues":["","superior", "test"]}]}
2
  • Can you provide the shortest possible data that doesn't deserialize properly, and as JSON text, rather than an image of it already parsed in some tool? Commented Sep 27, 2018 at 10:59
  • I edited my question and provide some example data now. Commented Sep 27, 2018 at 11:11

1 Answer 1

1

In Results_FullData, the property is called results, but in the example JSON, it's called result. Also, DSContent.userRunId is declared as a Long, even though in the JSON, that property contains String values. If you fix those two things in your data classes, it properly deserializes your example data:

Public Sub Main()
    Dim json As String = "{""result"":[{""userRunId"":""xxxxxxx"",""metaColumnValues"":[""9006409"",""20073""],""dataColumnValues"":["""",""superior""]},{""userRunId"":""xxxxxxx"",""metaColumnValues"":[""2345"",""235"",""1""],""dataColumnValues"":["""",""superior"", ""test""]}]}"
    Dim allData As Results_FullData = JsonConvert.DeserializeObject(Of Results_FullData)(json)
End Sub

Public Class Results_FullData
    Public Property result As List(Of DSContent)
End Class

Public Class DSContent
    Public Property userRunId As String
    Public Property metaColumnValues As List(Of String)
    Public Property dataColumnValues As List(Of String)
End Class
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect thats it! Thanks a lot!

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.