Wheelz Wheelz - 5 months ago 39
JSON Question

How to get items from array element json c#

How do i get items from array element json c# ?






I want to get multiple artist names from my call, and put them in a listbox.

I can get the first artist like this etc.:

string url = @"http://api.musixmatch.com/ws/1.1/artist.search?apikey=key&q_artist=LMFAO&format=json";
string content = new WebClient().DownloadString(url);
dynamic artistData = JObject.Parse(content);
string artistName = artistData.message.body.artist_list[0].artist.artist_name;


But how can i get more of the names and put them in a listbox?

Here you can see how the json result looks like

Thanks in advance

Answer

Thanks for trying to help me, I really appreciate it. I figured out i could solve my problem like this:

var artistLength = artistData.message.body.artist_list.Count;
    for (int i = 0; i < artistLength; i++)
    {
         var artistName = artistData.message.body.artist_list[i].artist.artist_name;

         //printed in the console for testing
         Console.WriteLine(artistName);
         listBox1.Items.Add(artistName);
    }