Jquery 将数组传递给Asp Web服务

Jquery 将数组传递给Asp Web服务,jquery,asp.net,Jquery,Asp.net,我有一个数组需要将该数组传递给我的ASP.Net Web服务 我的数组如下所示: { "lists" [ {"F0":"LpSeries", "F1":"Description"}, {"F0":"Second","F1":"StringValue"} ] } 我像这样使用javascript: $.ajax({ type: "POST", contentType: "application/json", data: js

我有一个数组需要将该数组传递给我的ASP.Net Web服务

我的数组如下所示:

{
    "lists" [
        {"F0":"LpSeries", "F1":"Description"},
        {"F0":"Second","F1":"StringValue"}
    ]
}
我像这样使用javascript:

$.ajax({
    type: "POST",
    contentType: "application/json",
    data: jsonText,
    url: "LPService.asmx/GetDataTableFromArray",
    dataType: "json",
    success: function (data) {
        alert(data.d);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        debugger;
    }
});
在webservice中,我这样写过

[WebInvoke(Method = "POST", UriTemplate = "")]
public DataTable X(RootObject root)
{
    DataTable dt = new DataTable();
    return dt;
    // do something with your root objects or its child objects...

    //return new HttpResponseMessage(HttpStatusCode.Created);
}
public class RootObject
{
    public List<Result> Results { get; set; }
}

public class Result
{
    public string F0 { get; set; }
    public string F1 { get; set; }
    public string F2 { get; set; }
    public string F3 { get; set; }
    public string F4 { get; set; }
    public string F5 { get; set; }
    public string F6 { get; set; }
    public string F7 { get; set; }
}
在这里,我为根对象创建了一个类,如下所示

[WebInvoke(Method = "POST", UriTemplate = "")]
public DataTable X(RootObject root)
{
    DataTable dt = new DataTable();
    return dt;
    // do something with your root objects or its child objects...

    //return new HttpResponseMessage(HttpStatusCode.Created);
}
public class RootObject
{
    public List<Result> Results { get; set; }
}

public class Result
{
    public string F0 { get; set; }
    public string F1 { get; set; }
    public string F2 { get; set; }
    public string F3 { get; set; }
    public string F4 { get; set; }
    public string F5 { get; set; }
    public string F6 { get; set; }
    public string F7 { get; set; }
}
我无法获取值。请帮助我如何解决此问题

请尝试以下方法:

var myArray1 = new Array();    
var myArray2 = new Array();    
data: "{'myArray1':"+JSON.stringify(myArray1)+",'myArray2':"+JSON.stringify(myArray2)+"}",
在您的webmethod中:

[System.Web.Services.WebMethod]
public static string SavePage(List<string> myArray1, List<string> myArray2)
{
return myArray1;
}

在以后的问题中,请注意正确格式化代码。它使其他人更容易快速阅读和理解您正在尝试做的事情。