using JavaScriptSerializer to serialize object to json
<script src="http://www.cnblogs.com/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript">
function test() {
var o = {};
o.name = "lie";
o.age = 22;
o.addresses = [];
o.addresses[0] = {};
o.addresses[0].country = "China";
o.addresses[0].city = "Shanghai";
o.addresses[1] = {};
o.addresses[1].country = "US";
o.addresses[1].city = "New York";
var json = Sys.Serialization.JavaScriptSerializer.serialize(o);
$.ajax({
url: "Home/Test2",
type: "POST",
data: json,
contentType: "application/json"
});
}
</script>
<script src="http://www.cnblogs.com/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript">
function test() {
var o = {};
o.name = "lie";
o.age = 22;
o.addresses = [];
o.addresses[0] = {};
o.addresses[0].country = "China";
o.addresses[0].city = "Shanghai";
o.addresses[1] = {};
o.addresses[1].country = "US";
o.addresses[1].city = "New York";
var json = Sys.Serialization.JavaScriptSerializer.serialize(o);
$.ajax({
url: "Home/Test2",
type: "POST",
data: json,
contentType: "application/json"
});
}
</script>