A JSON string is not just a complex string - it is serialized data (a class, dictionary, array etc). Nor can you ignore the parts you don't care about: your post leaves off a big chunk at the end.
In this case, it looks like it can be deserialized to a Dictionary, with the last element ("_links") itself being a dictionary. Looking at the text, the first element ("mature") is null, so I use Dictionary(Of String, Object)
:
Imports Newtonsoft.Json
' I downloaded it for ease, you could use the response
Dim json = File.ReadAllText("C:\Temp\MexxHD.json")
Dim col As Dictionary(Of String, Object)
col = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(json)
That's it really. Display the contents (remember at least one value is Nothing
):
For Each kvp As KeyValuePair(Of String, Object) In col
Console.WriteLine("Key: {0}, value: {1}", kvp.Key,
If(kvp.Value Is Nothing, "Null", kvp.Value.ToString))
Next
Output:
Key: mature, value: Null
Key: status, value: Chill
Key: broadcaster_language, value: en
Key: display_name, value: MexxHD
(etc)
The links part can be deserialized to its own dictionary:
Dim JLinks = col("_links").ToString
Dim linkCol As Dictionary(Of String, String)
linkCol = JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(JLinks)
Console.WriteLine("********* LINKS ********* ")
For Each kvp As KeyValuePair(Of String, String) In linkCol
Console.WriteLine("K: {0} V: {1}", kvp.Key, kvp.Value)
Next
Output:
********* LINKS *********
K: self V: https://api.twitch.tv/kraken/channels/mexxhd
K: follows V: https://api.twitch.tv/kraken/channels/mexxhd/follows
K: commercial V: https://api.twitch.tv/kraken/channels/mexxhd/commercial
(etc)
When the JSON appears to be an array of class objects, there are online tools which will create the class structure from the JSON string such as this one which will do VB classes
Just fetch the items you want from the Dictionary. Do keep in mind that some values can be Nothing
as is the case for "mature" which can lead to a NullReference Exception:
Label1.Text = col("status").ToString()