Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27405

VS 2015 Cannot deserialize the current JSON object

$
0
0
Hello, I get the error
HTML Code:

("Cannot deserialize the current JSON object (e.g. {""name"":""value""}) into type 'System.Collections.Generic.List`1[Rust_Tool.RustTool.WebSockets.Listserverinfo.Serverinfo]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly." & vbCrLf & "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." & vbCrLf & "Path 'Hostname', line 2, position 13."})
at the code place:
Code:

CurrentPlayers = JsonConvert.DeserializeObject(Of List(Of Serverinfo))(list)
I'm stuck and I don't know what to do :(

This is my code;
Code:

Imports Rust_Tool.RustTool.Callbacks

Namespace RustTool.WebSockets
    Public Class Listener
        Public Shared Listeners As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
        Public Shared NeedListener As List(Of String) = New List(Of String) From {"serverinfo"}
        Public Shared Sub ProcessMessage(ByVal packet As Packet)
            Dim command = Listeners(packet.Identifier)
            Listeners.Remove(packet.Identifier)
            Select Case (command.ToLower)
                Case "serverinfo"
                    PlayerList.UpdatePlayers(packet.Message)
            End Select
        End Sub
    End Class
End Namespace


Code:

Imports Rust_Tool.RustTool.Interface
Imports Newtonsoft.Json

Imports Rust_Tool.RustTool.WebSockets.Listserverinfo

Namespace RustTool.Callbacks
    Public Class PlayerList
        Public Shared CurrentPlayers As List(Of Serverinfo)

        Public Shared Sub UpdatePlayers(ByVal list As String)
            CurrentPlayers = JsonConvert.DeserializeObject(Of List(Of Serverinfo))(list) '<- ERROR
            PlayerDataTable.Update(CurrentPlayers)
        End Sub
    End Class
End Namespace

Code:

Imports Newtonsoft.Json

Namespace RustTool.WebSockets.Listserverinfo
    Public Class Serverinfo

        <JsonProperty("Hostname")>
        Public Property Hostname As String

        <JsonProperty("MaxPlayers")>
        Public Property MaxPlayers As Integer

    End Class

End Namespace


Viewing all articles
Browse latest Browse all 27405

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>