遍历 Twitch Json
Iterating through Twitch Json
我还不太擅长这个,不确定我的主题是否准确描述了我的需要。我知道它可能已经得到回答,我很难理解答案,因为它们并不直接适用于我的数据。我想弄清楚如何遍历此 URL.
中的数据
http://tmi.twitch.tv/group/user/twitch/chatters
这是我一直在用的。
Dim url = "http://tmi.twitch.tv/group/user/" & ConnectionInformation.Channel.TrimStart("#") & "/chatters"
Dim json As String = Nothing
Dim wc As New WebClient()
json = wc.DownloadString(url)
Dim root As JToken = JToken.Parse(json)
For Each item As JToken In root("chatters")
'I've tried several things here and I can't find a good way to iterate through the viewers found here.
Next
我想我无法让观众进入 collection 以便我可以遍历他们,有人可以在这里为我指明正确的方向吗?
谢谢。
"Chatters"其实就是根对象中的一个Type。如果您要创建 classes,它们将如下所示:
Public Class RootChatter
Public Property _links As _Links
Public Property chatter_count As Integer
Public Property chatters As Chatters
End Class
Public Class _Links
End Class
Public Class Chatters
Public Property moderators As String()
Public Property staff As String()
Public Property admins As String()
Public Property global_mods As String()
Public Property viewers As String()
End Class
Viewers 是 Chatters 中的一个数组 属性 (Root.Chatters.Viewers
)。没有 class:
Dim root As JToken = JToken.Parse(jstr)
Dim chatters = root("chatters")("viewers")
For n As Integer = 0 To chatters.Count - 1
Console.WriteLine(chatters(n))
Next
输出:
04paynem
0morningstar0
0rchlann
0riginus
10108abc
如果要反序列化为 classes:
Dim jc = JsonConvert.DeserializeObject(Of RootChatter)(jstr)
Dim viewers = jc.chatters.viewers
我还不太擅长这个,不确定我的主题是否准确描述了我的需要。我知道它可能已经得到回答,我很难理解答案,因为它们并不直接适用于我的数据。我想弄清楚如何遍历此 URL.
中的数据http://tmi.twitch.tv/group/user/twitch/chatters
这是我一直在用的。
Dim url = "http://tmi.twitch.tv/group/user/" & ConnectionInformation.Channel.TrimStart("#") & "/chatters"
Dim json As String = Nothing
Dim wc As New WebClient()
json = wc.DownloadString(url)
Dim root As JToken = JToken.Parse(json)
For Each item As JToken In root("chatters")
'I've tried several things here and I can't find a good way to iterate through the viewers found here.
Next
我想我无法让观众进入 collection 以便我可以遍历他们,有人可以在这里为我指明正确的方向吗?
谢谢。
"Chatters"其实就是根对象中的一个Type。如果您要创建 classes,它们将如下所示:
Public Class RootChatter
Public Property _links As _Links
Public Property chatter_count As Integer
Public Property chatters As Chatters
End Class
Public Class _Links
End Class
Public Class Chatters
Public Property moderators As String()
Public Property staff As String()
Public Property admins As String()
Public Property global_mods As String()
Public Property viewers As String()
End Class
Viewers 是 Chatters 中的一个数组 属性 (Root.Chatters.Viewers
)。没有 class:
Dim root As JToken = JToken.Parse(jstr)
Dim chatters = root("chatters")("viewers")
For n As Integer = 0 To chatters.Count - 1
Console.WriteLine(chatters(n))
Next
输出:
04paynem
0morningstar0
0rchlann
0riginus
10108abc
如果要反序列化为 classes:
Dim jc = JsonConvert.DeserializeObject(Of RootChatter)(jstr)
Dim viewers = jc.chatters.viewers