I am attempting to create objects out of the results of a query. Below is the class:
<JsonObject(MemberSerialization.OptIn)> Public Class User
<JsonProperty("@class")> Public ReadOnly _class As String = "User"
<JsonProperty("@rid")> Public ORID As String = ""
<JsonProperty("@version")> Public version As Integer
<JsonProperty()> Public UserID As String
End Class
Here is the JSON that is returned:
{"result":[{"@type":"d","@rid":"#-2:1","@version":0,"UserID":"123"}, {"@type":"d","@rid":"#-2:3","@version":0,"UserID":"456"}]}
Here is my code to deserialize using
JSON.NET:
Dim mee As List(Of User) = JsonConvert.DeserializeObject(Of List(Of User))(strReturn)
I am attempting to create a list/array/collection of objects (Users, in this case) from the result set of a query.
This is the error message when I deserialize:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[winFlickrFunkServer.User]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'result', line 1, position 10.
Any assistance with this will be greatly appreciated.