我有一个看起来像这样的json响应
{"RandomUsername1":
{"Name":"Aaron Baker","Team":"Mavericks","Town":"Chester","Scores":{"lowest":1,"highest":10,"average":5}},
"RandomUsername2":
{"Name":"Dan Williams","Team":"Lions","Town":"Doncaster","Scores":{"lowest":0,"highest":8,"average":4}},
"RandomUsername3":
{"Name":"Oliver Smith","Team":"Hudsons","Town":"Oxford","Scores":{"lowest":4,"highest":14,"average":9}}
}
当有1个键时,我一直在使用这个代码,但是当有多个键时,例如“RandomUsername1”,“RandomUsername2”,“RandomUsername3”我卡住了,不知道如何修改代码显示在一个listview列出了所有用户。
Imports Newtonsoft.Json
Imports app_functions
Imports System.Net
Public Class UserInfo
Private Const UserUrl As String = "https://www.anysitename/userinfo"
Public Shared Function GetUser() As UserInfo
If Not app_funcs.CanWeCallAPI Then
Return Nothing
End If
Dim www As New WebClient()
Dim res As Byte() = www.UploadValues(UserUrl, AuthHeader)
Dim strRes As String = System.Text.Encoding.UTF8.GetString(res)
Dim err As String = app_funcs.DetectError(strRes)
If Not String.IsNullOrEmpty(err) Then
Return Nothing
End If
Return Deserialize(strRes)
End Function
Public Shared Function Deserialize(json As [String]) As UserInfo
Return JsonConvert.DeserializeObject(Of UserInfo)(json)
End Function
End Class
如果有人能给我一些指示,我们将不胜感激。
谢谢,
安迪