Home > Mobile >  Problem foreach Windows Forms in Visual Studio 2019
Problem foreach Windows Forms in Visual Studio 2019

Time:03-20

I have a problem, and my problem is the following: I have this code in C# and I don't know how to do a foreach to get all pakFilename

WebClient client = new WebClient();

string strpagecode = client.DownloadString("https://fortnite-api.com/v2/aes");
dynamic dobj = JsonConvert.DeserializeObject<dynamic>(strpagecode);
string description = dobj["data"]["dynamicsKeys"][0]["pakFilename"].ToString();
aes.Text = description;

Could someone help me?

Thank you very much in advance

CodePudding user response:

Maybe it would help to use real objects instead of dealing with dynamic.

Generate c# classes from the JSON. Paste your json string to a tool like enter image description here

CodePudding user response:

Is this what you mean?

var dynamicsKeys = dobj["data"]["dynamicsKeys"];
foreach(var dynamicsKey in dynamicsKeys) {
    string pakFilename = dynamicsKeys["pakFilename"].ToString()
}
  •  Tags:  
  • c#
  • Related