Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This will work for you (full working code sample below). The key is to pass in a Person object. Also, I used a simple web service (myService.asmx) instead of an aspx page. Why bother with the extra overhead if it isn't needed?</p> <p>The key is, on the client, create a Person object and then use <a href="http://msdn.microsoft.com/en-us/library/cc836459%28v=vs.85%29.aspx" rel="nofollow">JSON.stringify</a> to pass the Person object to the webservice.</p> <p><strong>Javascript</strong></p> <pre><code>&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function BindJson() { $.ajax({ type: "POST", url: "myService.asmx/SerializeJson", data: JSON.stringify({ person:{ firstName: "Denny", lastName: "Cherian", department: "Microsoft PSS", address: { addressline1: "Microsoft India GTSC", addressline2: "PSS - DSI", city: "Bangalore", state: "Karnataka", country: "India", pin: "560028" }, technologies: ["IIS", "ASP.NET", "JavaScript", "AJAX"] }}), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data1) { alert(data1.d); }, error: function (request, status, errorThrown) { alert(status); } }); } $(document).ready(function() { BindJson(); }); &lt;/script&gt; </code></pre> <p><strong>C#</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace TestProject { /// &lt;summary&gt; /// Summary description for myService /// &lt;/summary&gt; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class myService : System.Web.Services.WebService { [WebMethod] public string SerializeJson(Person person) { return "Success"; } public class Person { public string firstName { get; set; } public string lastName { get; set; } public string department { get; set; } public Address address { get; set; } public string[] technologies { get; set; } } public class Address { public string addressline1 { get; set; } public string addressline2 { get; set; } public string city { get; set; } public string state { get; set; } public string country { get; set; } public string pin { get; set; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload