几天来,我一直在为一个问题烦恼,我对此感到非常沮丧!我想知道如何在 VB.NET 4.5 Framework 中解码 JSON 数组。我正在尝试使用反序列化/序列化类。这是数组:
{"LaunchIDs":["2","3","4","5","6","7","8","9","10"],"FavoriteID":null,"用户名":"Test","error":0,"message":"您已成功登录"}
数组的代码是
Public Class JSONCode
Public LaunchIDs As Integer
Public FavoriteIDAs Integer
Public username As String
Public [error] As Integer
Public message As Integer
End Class
这是我在应用程序中使用它的方式。
Dim client As New WebClient()
Dim jsonResponse As String = "{""LaunchIDs"":[""2"",""3"",""4"",""5"",""6"",""7"",""8"",""9"",""10""],""FavoriteID"":null,""username"":""Test"",""error"":0,""message"":""You have successfully logged in""}")
Dim serializer As New JavaScriptSerializer()
Dim response As JSONCode = serializer.Deserialize(Of JSONCode)(jsonResponse)
code = response.error
If code = 0 & response.message = "You have successfully logged in" Then
LoginFunction = True
botids = response.botids
ListBox1.AddItem(botids)
Else
Alert(Style.Critical, response.message)
End If
End If
该数组将从一个网址中检索(在我解决了这个问题之后),所以它现在有点乱。Alert() 只是一个小的自定义 msgBox 函数。
尝试调试时出现此错误。数组的反序列化不支持类型“System.Int32”。