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为空

{

&

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐