VB.NET 正在解析 JSON - 电报

VB.NET Parsing JSON - Telegram

我正在尝试创建一个 Telegram 机器人 VB.NET,但在解析 JSON 时遇到问题。首先,这是我从 Telegram 获得的 JSON 的示例:

    {
        "ok": true,
        "result": [
            {
                "update_id": 999999999,
                "message": {
                    "message_id": 99,
                    "from": {
                        "id": 999999999,
                        "first_name": "Adam",
                        "last_name": "Taveirne",
                        "username": "xxxxxxxxxxxxxx",
                        "language_code": "en-US"
                    },
                    "chat": {
                        "id": 99999999,
                        "first_name": "Adam",
                        "last_name": "Taveirne",
                        "username": "xxxxxxxxxxx",
                        "type": "private"
                    },
                    "date": 1500281934,
                    "text": "Hello"
                }
            }
        ]
    }

我正在努力寻求有关解析格式如下的 JSON 的帮助。每当我尝试解析结果数组时,我都会收到 "Cannot deserialize the current JSON array" 错误。

我尝试了一堆不同的代码并得到了类似的错误,但这是我最近的尝试:

Sub Main()

//Crap cut out here...

Dim obj = JsonConvert.DeserializeObject(Of MyTeleJSON)(json)

End Sub

Public Class MyTeleJSON
    Public Property ok As String
    Public Property result As MyTeleUpdates
End Class

Public Class MyTeleUpdates
    Public Property update_id As String
    Public Property message_id As String
    Public Property id As String
    Public Property first_name As String
    Public Property last_name As String
    Public Property username As String
    Public Property text As String
    Public Property ok As String
End Class

有人能给我指明正确的方向吗,因为我真的在为这个 JSON 问题苦苦挣扎!

非常感谢

亚当

这应该是需要的类。您的 "ok" 属性 可能破坏了解析,因为它是一个布尔值。

Public Class From
    Public Property id As Integer
    Public Property first_name As String
    Public Property last_name As String
    Public Property username As String
    Public Property language_code As String
End Class

Public Class Chat
    Public Property id As Integer
    Public Property first_name As String
    Public Property last_name As String
    Public Property username As String
    Public Property type As String
End Class

Public Class Message
    Public Property message_id As Integer
    Public Property from As From
    Public Property chat As Chat
    Public Property date As Integer
    Public Property text As String
End Class

Public Class Result
    Public Property update_id As Integer
    Public Property message As Message
End Class

Public Class Example
    Public Property ok As Boolean
    Public Property result As List(of Result)
End Class