如何在c#webmethod中传递和获取多维数组 [英] how to pass and get the multidimensional array in c# webmethod

查看:89
本文介绍了如何在c#webmethod中传递和获取多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#web方法中发送和处理多维数组,因为我已经做了一些工作.我不想循环运行ajax函数.

I want to send and work on multidimensional array in c# webmethod for that i have done some work.I dont want to run the ajax function in loop.

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]
    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)

这篇关于如何在c#webmethod中传递和获取多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆