VB.NET反序列化获取信息

嗨,我在从此Json中提取信息时遇到了麻烦:

http://monitor.sacnr.com/api/?IP=198.50.195.141&Port=7790&Action=info

我正在使用导入system.web.Script.Serialization ,这就是我所做的:

<Serializable()>
Public NotInheritable Class MyType
    Public Property ServerID As String
    Public Property IP As String
    Public Property Port As Integer
    Public Property Hostname As String
    Public Property Gamemode As String
    Public Property Language As String
    Public Property Map As String
    Public Property MaxPlayers As Integer
    Public Property Players As Integer
    Public Property Version As String
    Public Property Password As Integer
    Public Property Time As String
    Public Property WebURL As String
    Public Property Rank As Integer
    Public Property AvgPlayers As String
    Public Property HostedTab As Integer
    Public Property LastUpdate As String
    Public Property TotalServers As Integer
    Public Sub New()
    End Sub

    Public Overrides Function ToString() As String
        Return New JavaScriptSerializer().Serialize(Me).ToString
    End Function
End Class


Public Sub GetServerdata()

    Dim WebClient = New WebClient
    AddHandler WebClient.DownloadStringCompleted,AddressOf webClient_DownloadStringCompleted
    WebClient.DownloadStringAsync(New Uri("http://monitor.sacnr.com/api/?IP=198.50.195.141&Port=7790&action=info"))

End Sub

Public Sub webClient_DownloadStringCompleted(ByVal sender As Object,ByVal e As DownloadStringCompletedEventArgs)
    Try
        Dim JsonCode As String = e.Result
        'MsgBox(JsonCode)
        If Not JsonCode = "" Then

             Dim obj As MyType = New JavaScriptSerializer().Deserialize(Of MyType)(e.Result)

            ServerIDlvl.Text = obj.ServerID
            ThirteenTextBox2.Text = obj.IP & ":" & obj.Port
            Playerslvl.Text = obj.Players & "/" & obj.MaxPlayers
             modelvl.Text = obj.Gamemode
            Hostnamelvl.Text = obj.Hostname
              Timelvl.Text = obj.Time
              Maplvl.Text = obj.Map
              WebURLlvl.Text = obj.WebURL
              Versionlvl.Text = obj.Version
             Languagelvl.Text = obj.Language
             If obj.Password = 0 Then
            'Panel4.BackgroundImage = My.Resources.open
               Else
            'Panel4.BackgroundImage = My.Resources.Locked
             End If

        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

但这对我不起作用,原始杰森告诉我。

谢谢。

Venus0808 回答:VB.NET反序列化获取信息

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3044136.html

大家都在问