title: How to pass JSON object using Ajax with ASP.NET WebMethod
body: <p>I have a problem with passing a JSON object using Ajax and ASP.NET WebMethods</p>
  
  <pre><code>function setStudentInfo() {
      var jsonObjects = [
          { id: 1, name: "mike" },
          { id: 2, name: "kile" },
          { id: 3, name: "brian" },
          { id: 1, name: "tom" }
      ];
  
      $.ajax({
          type: "POST",
          url: "ConfigureManager.aspx/SetStudentInfo",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          async: false,
          data: { students: JSON.stringify(jsonObjects) },
          success: function (result) {
              alert('success');
          },
          error: function (result) {
              alert(result.responseText);
          }
  
      });
  }
  </code></pre>
  
  <p>ASP.NET code</p>
  
  <pre><code>[WebMethod]
  public static void SetStudentInfo(object students)
  {
       //Here I want to iterate the 4 objects and to print their name and id
  }
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <blockquote>
    <p>"{"Message":"Invalid JSON primitive: students.","StackTrace":"   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
       at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
          at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
             at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
                at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)
                   at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)
                      at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)
                         at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}"</p>
  </blockquote>