0

我有数组需要将该数组传递给我的 ASP.Net Webservice

我的数组如下所示:

{
    "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;
    }
});

在网络服务中,我这样写

[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; }
}

我无法获得价值。请帮我解决这个问题

4

1 回答 1

0

尝试这样做:

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

在您的网络方法中:

[System.Web.Services.WebMethod]
public static string SavePage(List<string> myArray1, List<string> myArray2)
{
return myArray1;
}
于 2012-04-17T08:43:32.280 回答