日期:2014-05-17  浏览次数:20617 次

Ajax传递Json数据之后无法用string类型进行接收,百分送上
用jqueryAjaxPost了一个json数据.
大概的demo简化了一下变成这样


var json='{ "menu":[{"Role_ID":"2","Customer_ID":"155","Brands":"Chloe;","Country_ID":"96;"},{"Role_ID":"-1","Customer_ID":"497","Brands":"Chloe;","Country_ID":"96;"}]}';
 $.ajax({
                url: "RoleFunc.aspx/Convert",
                    type: "POST",
                    contentType: "application/json",
                    dataType: 'json',
                    data: '{"strJson":' + json+ '}',
                   

                    success: function(result) {
                        alert(result);

                    },
                    error: function() {
                        alert("error");
                    }
                });


我想用后台去处理这一条js数据.但是我用string作为参数的时候会出现
No parameterless constructor defined for type of 'System.String'.
这样的错误.我自定义了一个Class之后

 public class CustomerRole
        {
            public string Role_ID { get; set; }
            public string Customer_ID { get; set; }
            public string Brands { get; set; }
            public string Country_ID { get; set; }
        }

后台测试方法

 [WebMethod]
        public static string Convert(string strJson)//error
        {


            return strJson;

        }
[WebMethod]
        public static string Convert(CustomerRole strJson)//可以,但是这个strJson的obj为空
        {


        &