title: Looping through List<Objects> in a JSON API call (CrunchBase)
body: <p>Firstly to make this helpful to anyone wanting to get to this point:
  I have an API I need to query for various data points (CrunchBase) I took the URL and generated the classes for it using this tool <a href="http://json2csharp.com/#" rel="nofollow">http://json2csharp.com/#</a> (returns the classes you need to interact with that JSON URL) Next I needed to consume the service, enter Scott Hanselman to the rescue, used his blog article on how to do this <a href="http://www.hanselman.com/blog/NuGetPackageOfTheWeek4DeserializingJSONWithJsonNET.aspx" rel="nofollow">http://www.hanselman.com/blog/NuGetPackageOfTheWeek4DeserializingJSONWithJsonNET.aspx</a> Next I put the two together, and did some tinkering to allow me to query the CrunchBase API for partof the information that is needed. Currently I'm just working out the logic with a console app as I intend to wrap this in a .dll later for use in the DAL layer of a DataModel project that provides the info to an MVC site.</p>
  
  <p>The question: This so far works except for I don't know what I should do to loop through the subObjects returned from the JSON endpoint. My code is posted as is for anyone that wants to see the implementation ( I could not find an example ANYWHERE on the net for calling the CrunchBase API in C#) This code is commented at the spots I know that need to have some kinda foreach loop but all the examples I have found do not work for me. Any direction on how to do this is much appreciated. An example or a code correction would go a long way towards helping myself and anyone else figure out the rest on our own. Additional question, can this be all done in c# or do i need to use something else- if so any resourced you can recommend for additional followup study?</p>
  
  <p>The endpoint used in this code is "http://api.crunchbase.com/v/1/company/" + CompanyName +".js"  Thank you very much in advance, I tried long and hard before asking.</p>
  
  <pre><code>....
  using System.Net;
  using Newtonsoft.Json;
  
   namespace CrunchBase
   {
      class Program
      {
         static void Main(string[] args)
         {
             Console.WriteLine("Enter the name of a Company to look up:");
             string CompanyName = Console.ReadLine();
  
             var client = new WebClient();
             client.Headers.Add("User-Agent", "Nobody"); //my endpoint needs this...
             var response = client.DownloadString(new Uri("http://api.crunchbase.com/v/1/company/" + CompanyName +".js"));
  
             var j = JsonConvert.DeserializeObject&lt;RootObject&gt;(response);
             var f = JsonConvert.DeserializeObject&lt;FundingRound&gt;(response);
             var i = JsonConvert.DeserializeObject&lt;Investment&gt;(response);
  
                 Console.WriteLine("Company Name: {0}", j.name);
                 Console.WriteLine("Web Page: {0}", j.homepage_url);
                 Console.WriteLine("Email Adress: {0}", j.email_address);
                 Console.WriteLine("CruchBase Page: {0}", j.crunchbase_url);
                 Console.WriteLine("Category: {0}", j.category_code);
                 Console.WriteLine("Description: {0}", j.description);
                 Console.WriteLine("Number of Employees: {0}", j.number_of_employees);
                 Console.WriteLine("Year Founded: {0}", j.founded_year);
                 // How would the best aproach be to loop through all of the Objects and print their properties?
                 // By the way, if you run this it will hang a little bit because the FundingRound object is not 
                 // properly implemented at the moment.
                 Console.WriteLine("Funding Round Type: {0}", f.round_code);
                 Console.WriteLine("Information Source: {0}", f.source_url);
                 Console.WriteLine("Description: {0}", f.source_description);
                 Console.WriteLine("Raised Amount: {0} {1}", f.raised_currency_code, f.raised_amount);
                 // I take it the same technique used to loop  through the above "f" var object 
                 // I would use again to loop through to the next nested Investment   object
                 // and on down the chain fefore returning right back up....
  
                 Console.ReadLine(); 
         }
  
         public class Image
         {
             public List&lt;List&lt;object&gt;&gt; available_sizes { get; set; }
             public object attribution { get; set; }
         }
  
         public class Person
         {
             public string first_name { get; set; }
             public string last_name { get; set; }
             public string permalink { get; set; }
         }
  
         public class Relationship
         {
             public bool is_past { get; set; }
             public string title { get; set; }
             public Person person { get; set; }
         }
  
         public class Provider
         {
             public string name { get; set; }
             public string permalink { get; set; }
         }
  
         public class Providership
         {
             public string title { get; set; }
             public bool is_past { get; set; }
             public Provider provider { get; set; }
         }
  
         public class FinancialOrg
         {
             public string name { get; set; }
             public string permalink { get; set; }
         }
  
         public class Person2
         {
             public string first_name { get; set; }
             public string last_name { get; set; }
             public string permalink { get; set; }
         }
  
         public class Investment
         {
             public object company { get; set; }
             public FinancialOrg financial_org { get; set; }
             public Person2 person { get; set; }
         }
  
         public class FundingRound
         {
             public string round_code { get; set; }
             public string source_url { get; set; }
             public string source_description { get; set; }
             public double raised_amount { get; set; }
             public string raised_currency_code { get; set; }
             public int funded_year { get; set; }
             public int funded_month { get; set; }
             public int funded_day { get; set; }
             public List&lt;Investment&gt; investments { get; set; }
         }
  
         public class Office
         {
             public string description { get; set; }
             public string address1 { get; set; }
             public string address2 { get; set; }
             public string zip_code { get; set; }
             public string city { get; set; }
             public string state_code { get; set; }
             public string country_code { get; set; }
             public object latitude { get; set; }
             public object longitude { get; set; }
         }
  
         public class VideoEmbed
         {
             public string embed_code { get; set; }
             public string description { get; set; }
         }
  
         public class Screenshot
         {
             public List&lt;List&lt;object&gt;&gt; available_sizes { get; set; }
             public object attribution { get; set; }
         }
  
         public class RootObject 
         {
             public string name { get; set; }
             public string permalink { get; set; }
             public string crunchbase_url { get; set; }
             public string homepage_url { get; set; }
             public string blog_url { get; set; }
             public string blog_feed_url { get; set; }
             public string twitter_username { get; set; }
             public string category_code { get; set; }
             public int number_of_employees { get; set; }
             public int founded_year { get; set; }
             public int founded_month { get; set; }
             public object founded_day { get; set; }
             public object deadpooled_year { get; set; }
             public object deadpooled_month { get; set; }
             public object deadpooled_day { get; set; }
             public object deadpooled_url { get; set; }
             public string tag_list { get; set; }
             public string alias_list { get; set; }
             public string email_address { get; set; }
             public string phone_number { get; set; }
             public string description { get; set; }
             public string created_at { get; set; }
             public string updated_at { get; set; }
             public string overview { get; set; }
             public Image image { get; set; }
             public List&lt;object&gt; products { get; set; }
             public List&lt;Relationship&gt; relationships { get; set; }
             public List&lt;object&gt; competitions { get; set; }
             public List&lt;Providership&gt; providerships { get; set; }
             public string total_money_raised { get; set; }
             public List&lt;FundingRound&gt; funding_rounds { get; set; }
             public List&lt;object&gt; investments { get; set; }
             public object acquisition { get; set; }
             public List&lt;object&gt; acquisitions { get; set; }
             public List&lt;Office&gt; offices { get; set; }
             public List&lt;object&gt; milestones { get; set; }
             public object ipo { get; set; }
             public List&lt;VideoEmbed&gt; video_embeds { get; set; }
             public List&lt;Screenshot&gt; screenshots { get; set; }
             public List&lt;object&gt; external_links { get; set; }
         }
      }
   }
  </code></pre>