我想在c# webmethod中发送和工作多维数组,为此我已经做了一些工作。我不想在循环中运行ajax函数。
ASPX页面代码
var trip_id = $("#example1").val();
var user_id = $("#example2").val();
var facebookData = [];
facebookData[0] = trip_id;
facebookData[1] = user_id;
var fnds_list_array=[];
fnds_list_array=[["0678678678","XYZ","something.jpg"],["432524352","ABC","somethingABC.jpg"]]
var jsonData = JSON.stringify({ fb_Data: facebookData, fb_user_data: fnds_list_array });
$.ajax({
type: "POST",
url: "Ajax_function/myfunction.asmx/insert_custom",
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess_insert_custom,
error: OnErrorCall
});
function OnErrorCall()
{ console.log("OHHH there is a mistake");}
function OnSuccess_insert_custom(response)
{ console.log("SUCESS");}
Webmethod Code
[WebMethod]
public string[] insert_custom(List<string> fb_Data,List<string> fb_user_data)
{
string temp = "";
string tripid = fb_Data[0];
string owner_id = fb_Data[1];
string fb_all_data;
string fb_id_user;
string fb_name;
string fb_img_src;
for (int i = 0; i < fb_user_data.Count; i++)
{
fb_all_data=fb_user_data[i];
string[] spltVal = fb_all_data.Split(',');
for (int j = 0; j < spltVal.Length; j++)
{
fb_id_user=spltVal[0];
fb_name = spltVal[1];
fb_img_src = spltVal[2];
temp = inFn.insert_custom(tripid, owner_id, fb_id_user, fb_name, fb_img_src);
}
}
// }
string[] arr1 = new string[] { temp };
return arr1;
}
但是我得到以下错误
"Type 'System.String' is not supported for deserialization of an array."
注意: fnds_list_array
不是静态的。它可以增加或减少
你可以这样做
MyWebMethod(List<List<string>> fnds_list_array)
看下面的例子,我无法测试它。但它可以给你一些解决问题的方法。
[WebMethod]
public static string[] insert_custom(List<MyTest> fnds_list_array)
{
}
public class MyTest
{
publc int Id
{ get; set;}
publc string Name
{ get; set;}
publc string ImageName
{ get; set;}
}