[英]how to pass and get the multidimensional array in c# webmethod
我想在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");}
Web方法代碼
[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;}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.