title: How do you pass and receive a nested array of objects using AJAX (jquery) into a c# WebMethod?
body: <p>I'm trying to pass some data to a WebMethod in a Code Behind <code>.cs</code> file. The data resembles the object below, where there's an array that can have any number of additional objects.</p>
  
  <pre><code>var data = {
      id: "123",
      formula: "liquid",
      chemicals: [
          {
              id: "223",
              amount: "0.2",
              units: "lb/gal",
          }, 
          {
              id: "363",
              amount: "8.8",
              units: "g/li",
          }
      ]
  };
  </code></pre>
  
  <p>The ajax method looks like this:</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "index.aspx/SaveData",
      data: JSON.stringify(data),
      contentType: "application/json; charset=utf-8",
      dataType: "json"
  });
  </code></pre>
  
  <p>Where I'm struggling is the WebMethod definition to receive the array of objects. </p>
  
  <p>When I simply send over the top level strings <code>id</code> and <code>formula</code>, it works fine. That web method looks predictable:</p>
  
  <pre><code>[WebMethod]
  public static string SaveData(string id, string formula)
  {
      // do cool stuff
  }
  </code></pre>
  
  <p>When I try to include the <code>chemicals</code> array, I get a failure response. I'm not sure how to match it. I've tried <code>string</code>, <code>string[]</code>, and a few others. Any thoughts on how to properly receive this data in a WebMethod? </p>