title: How to iterate through a List and convert it to a JSON object using JSON.NET (C# / ASP.NET)
body: <p>I have the following Object:</p>
  
  <pre><code>[Serializable]
  public class Project
  {
      private int projectId;
      private int userId;
      private String projectName;
      private String projectDescription;
      private DateTime startDate;
      private DateTime endDate;
  
  ...constructor + get/set methods removed
  </code></pre>
  
  <p>}</p>
  
  <p>I have a a Class which has a variable:</p>
  
  <pre><code>private List&lt;Project&gt; projects
  </code></pre>
  
  <p>The corresponding get method is</p>
  
  <pre><code>public List&lt;Project&gt; getUserProjects()
      {
          return projects;
      }
  </code></pre>
  
  <p>I'm trying to convert this List to a JSON format to use with an AJAX service but the result is always [{},{}] (The user has 2 projects - if 3 than the result is [{},{},{}]</p>
  
  <p>This is how I serialize the list of objects using JSON.NET:</p>
  
  <pre><code>[OperationContract]
  public string GetProjects()
      {
           string json = JsonConvert.SerializeObject(user.getUserProjects());
           return json;
      }
  </code></pre>
  
  <p>Should I iterate through the list first or...?
  Any help will be greatly appreciated!</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: </p>
  
  <p>I would like the JSON output to be like:</p>
  
  <pre><code>{
  "Projects": [
  { "ProjectID":"theID" , "userID":"theuserID" , "ProjectName":"theName" , "ProjectDescription":"theDescription" , "startDate":"thedate" , "endDate":"theDate" }, 
  { "ProjectID":"theID" , "userID":"theuserID" , "ProjectName":"theName" , "ProjectDescription":"theDescription" , "startDate":"thedate" , "endDate":"theDate" }, 
  ...etc
  ]
  }
  </code></pre>