title: How to loop through nested JSON objects in C#?
body: <p>I am working on a C# project where I need to call an API and parse through the JSON response.</p>
  <p>The JSON response:</p>
  <pre><code>{
      &quot;version&quot;: &quot;3.9.1&quot;,
       &quot;data&quot;: {
          &quot;obj1&quot;: {
              &quot;version&quot;: &quot;1.0.0&quot;,
              &quot;id&quot;: &quot;obj1&quot;,
              &quot;name&quot;: &quot;Object 1&quot;,
              &quot;title&quot;: &quot;Object 1&quot;,
              &quot;info&quot;: {
                  &quot;info1&quot;: 8,
                  &quot;info2&quot;: 4,
                  &quot;info3&quot;: 3
              },
              &quot;image&quot;: {
                  &quot;full&quot;: &quot;Object1.png&quot;,
                  &quot;w&quot;: 64,
                  &quot;h&quot;: 64
              },
              &quot;tags&quot;: [
                  &quot;Tag1&quot;,
                  &quot;Tag2&quot;
              ]
          },
          &quot;obj2&quot;: {
              &quot;version&quot;: &quot;1.0.0&quot;,
              &quot;id&quot;: &quot;obj2&quot;,
              &quot;name&quot;: &quot;Object 2&quot;,
              &quot;title&quot;: &quot;Object 2&quot;,
              &quot;info&quot;: {
                  &quot;info1&quot;: 1,
                  &quot;info2&quot;: 6,
                  &quot;info3&quot;: 7
              },
              &quot;image&quot;: {
                  &quot;full&quot;: &quot;Object2.png&quot;,
                  &quot;w&quot;: 64,
                  &quot;h&quot;: 64
              },
              &quot;tags&quot;: [
                  &quot;Tag1&quot;,
                  &quot;Tag6&quot;
              ]
          },
          &quot;obj3&quot;: {
              &quot;version&quot;: &quot;1.0.0&quot;,
              &quot;id&quot;: &quot;obj3&quot;,
              &quot;name&quot;: &quot;Object 3&quot;,
              &quot;title&quot;: &quot;Object 3&quot;,
              &quot;info&quot;: {
                  &quot;info1&quot;: 0,
                  &quot;info2&quot;: 1,
                  &quot;info3&quot;: 2
              },
              &quot;image&quot;: {
                  &quot;full&quot;: &quot;Object3.png&quot;,
                  &quot;w&quot;: 64,
                  &quot;h&quot;: 64
              },
              &quot;tags&quot;: [
                  &quot;Tag7&quot;,
                  &quot;Tag8&quot;
              ]
          }
      }
  }
  </code></pre>
  <p>With this response, I want to loop through all the objects located inside <code>data</code>. The number of objects inside <code>data</code> isn't always the same; it is possible that there will only be one object or ten objects.</p>
  <p>The problem I ran into is that I can't loop through the <code>data</code> property because of the following error:</p>
  <blockquote>
  <p>foreach statement cannot operate on variables of type 'Objects' because 'Objects' does not contain a public instance or extension definition for 'GetEnumerator'</p>
  </blockquote>
  <p>I know why I am getting the error, but I can't find a way of fixing my problem.</p>
  <p>My code:</p>
  <p><strong>MainWindow.xaml.cs</strong></p>
  <pre><code>WebRequest request = WebRequest.Create(path);
  WebResponse response = request.GetResponse();
  StreamReader reader = new StreamReader(response.GetResponseStream());
  
  string ReaderJson = reader.ReadToEnd();
  
  var JsonResponse = JsonConvert.DeserializeObject&lt;Response&gt;(ReaderJson);
  
  foreach (var obj in JsonResponse.data)
  {
      Console.WriteLine(obj.ToString());
  }
  </code></pre>
  <p><strong>JsonParser.cs</strong></p>
  <pre><code>    public class Response
      {
          public string version { get; set; }
          public Objects data { get; set; }
      }
  
      public class Objects
      {
          public string id { get; set; }
          public string name { get; set; }
          public string title { get; set; }
          public Info info { get; set; }
          public Images images { get; set; }
      }
  
      public class Info
      {
          public int info1 { get; set; }
          public int info2 { get; set; }
          public int info3 { get; set; }
      }
  
      public class Images
      {
          public string full { get; set; }
          public int w { get; set; }
          public int h { get; set; }
      }
  </code></pre>
  <p>How can I loop through all the objects inside <code>data</code> without calling them using <code>obj1</code>, <code>obj2</code>, etc.?</p>