Ben Ben - 1 year ago 64 Question

Deserializing Json VB.NET

I am trying to deserialize data from a webserver for a game launcher.

The API docs provide me the data in json format, but I have been struggling to be able to read that data I am given and store it as a variable to use to log in a player. I have also tried a few other things but I am just stuck now.

Normally a response from the server would like like this:


The code to deserialize the data:

Dim result() As TTRServerResponse = JsonConvert.DeserializeObject(Of TTRServerResponse())(responseFromServer)

Class with the variables I want to store

Public Class TTRServerResponse
Public Property success As String
Public Property eta As String
Public Property position As String
Public Property queueToken As String
Public Property cookie As String
End Class

Any ideas where I messed up or what I should do? Thanks, Ben.

Answer Source

You are trying to deserialize the JSON into an array but in your example it is a single object.

So assuming

Dim responseFromServer As String

is equal to


Which, according to the documentation you linked to, is suppose to be a single object,

then you need to update your code to deserialize a single object as appose to an array

Dim result As TTRServerResponse = JsonConvert.DeserializeObject(Of TTRServerResponse)(responseFromServer)