0
我有一个脚本,它返回JSON中的数据数组,如下所示。POST JSON数组到ASP.NET WebMethod
[
{"ItemID":"10319","ItemCode":"ITEM-010318","Qty":"1","custRef":"12 - Mitsubishi Fighter FK61F"},
{"ItemID":"10933","ItemCode":"ITEM-010932","Qty":"1","custRef":"12 - Mitsubishi Fighter FK61F"},{"ItemID":"10537","ItemCode":"ITEM-010536","Qty":"1","custRef":"12 - Mitsubishi Fighter FK61F"},
{"ItemID":"14863","ItemCode":"ITEM-014862","Qty":"1","custRef":"12 - Mitsubishi Fighter FK61F"},
{"ItemID":"14864","ItemCode":"ITEM-014863","Qty":"1","custRef":"12 - Mitsubishi Fighter FK61F"}
]
此数据存储在一个名为cartData
我然后将数据推到通过AJAX我的WebMethod变量,如下所示
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "OrderFormServices.asmx/AddItemsToCart",
data: JSON.stringify(cartData),
dataType: "json"
});
我的Web方法看起来像这样
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void AddItemsToCart(string [] itemID, string [] itemCode, string [] Qty, string [] custRef)
但是,当我尝试和POST数据时,控制台上出现错误我无法做到头或尾!任何人都可以点亮它吗?
Type 'System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089],
[System.Object, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
is not supported for deserialization of an array.
谢谢,我已经编辑按你的第二个建议,现在我使用 'cartData.push( { 'ITEMID':itemIdVal, 'itemCode':itemCodeVal, '数量':qtyVal, 'custRef':custRefVal });'然而这似乎并不奏效 - cartData.push不是一个函数? –
这不会工作,它会这样工作: cartData.push({'itemID':[itemIdVal],'itemCode':[itemCodeVal],'qty':[qtyVal],'custRef':[custRefVal]} ); 也要确保param的名称与web方法相同,例如:数量。 – MoustafaS
我得到'cartData.push'不是一个函数吗? –