Javascript 将参数作为JSON对象传递给WebMethod

Javascript 将参数作为JSON对象传递给WebMethod,javascript,c#,json,Javascript,C#,Json,当我将参数传递给我的WebmMethod时,会出现各种错误。以下是我的各种尝试和错误: globalData是一个数组,mapping是一个可以反序列化到列表的数组,selectedFund是一个整数 C#WebMethod [WebMethod] public static void ProcessData(string data, List<Mapping> mapping, int selectedFund) { //blah blah } 错误:系统。数组序列化不支

当我将参数传递给我的
WebmMethod
时,会出现各种错误。以下是我的各种尝试和错误:

globalData
是一个数组,
mapping
是一个可以反序列化到
列表的数组,
selectedFund
是一个整数

C#WebMethod

[WebMethod]
public static void ProcessData(string data, List<Mapping> mapping, int selectedFund)
{
    //blah blah
}
错误:
系统。数组序列化不支持字符串

尝试2次

$.ajax({
//... etc...
    data: {
        data: JSON.stringify(globalData),
        mapping: JSON.stringify(chosenMappings),
        selectedFund: $selectedFund.val()
    },
    contentType: "application/json; charset=utf-8",

错误:无效的Json原语

您缺少jQuery Json帖子中的内容类型:

contentType: "application/json; charset=utf-8",
检查这篇文章

http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

我想出来了。。。我需要做两次
JSON.stringify()
。一次在外面,然后一次在里面

contentType: "application/json; charset=utf-8",
type: 'POST',
dataType: "json",
//data: JSON.stringify(payload),
data: JSON.stringify({
    data: JSON.stringify(globalData),
    mapping: JSON.stringify(chosenMappings),
    selectedFund: $selectedFund.val()
}),

抱歉,我的contentType中确实包含了这些内容。
contentType: "application/json; charset=utf-8",
type: 'POST',
dataType: "json",
//data: JSON.stringify(payload),
data: JSON.stringify({
    data: JSON.stringify(globalData),
    mapping: JSON.stringify(chosenMappings),
    selectedFund: $selectedFund.val()
}),