Jquery Ajax json Serializable
Posted
by
willsonchan
on Stack Overflow
See other posts from Stack Overflow
or by willsonchan
Published on 2013-11-05T14:40:51Z
Indexed on
2013/11/05
15:53 UTC
Read the original article
Hit count: 315
I am learing using jquery ajax to hander the JSON..i writre a demo code. HTMLCODE
$(function () {
$("#add").click(function () {
var json = '{ "str":[{"Role_ID":"2","Customer_ID":"155","Brands":"Chloe;","Country_ID":"96;"}]}';
$.ajax({
url: "func.aspx/GetJson",
type: "POST",
contentType: "application/json",
dataType: 'json',
data: json,
success: function (result) {
alert(result);
},
error: function () {
alert("error");
}
});
});
});
<div>
<input type="button" value="add" id="add" />
</div>
i got a input and bind a script function to it, now the proble is comeing.. my C# functiong like that.
[WebMethod]
public static string GetJson(object str)
{
return str.ToString();//good for work
}
[Serializable]
public class TestClass
{
public TestClass()
{
}
public TestClass(string role_id, string customer_id, string brands, string countryid)
{
this.Role_ID = role_id;
this.Customer_ID = customer_id;
this.Brands = brands;
this.Country_ID = countryid;
}
public string Role_ID { get; set; }
public string Customer_ID { get; set; }
public string Brands { get; set; }
public string Country_ID { get; set; }
}
when i user public static string GetJson(object str) everything is so good.~~ no error at all but . when i try to use my own class TestClass. firebug tell me that "Type 'TestClass' is not supported for deserialization of an array." .any body can give me help:XD
© Stack Overflow or respective owner