簡體   English   中英

C#和Javascript傳遞數據

[英]C# and Javascript Pass DATA

我的C#應用​​程序提供數據並將其發送到WebService,如下所示:

list.Add('cool'); //add value to the list
list.Add('whau'); //add value to the list
Service.sendList(list.ToArray()); //send list to the WebService called Service using the WebMethod  sendList()

我通過Javascript函數中的WebService檢索此數據的方式如下:

 WebService.getList(OnSucceeded,OnFailed);
 function OnSucceeded(result){
 var data = result[0];  //result[0] = 'cool';
 var data2 = result[1]; //result[1] = 'whau';
 }
 function OnFailed(result){
 //do nothing
 }

現在,我需要這樣的var數據:

var data = [['january', 2,3],['february', 3,5],['march', 5, 10]];

我如何需要將其從C#發送到WebService以便最后獲得上面的var數據?

謝謝你的幫助 !

您將需要將數據作為二維數組發送。

var list = new List<List<string>>();
list.Add(new List<string>());

list[0].Add("january");
list[0].Add("2");
list[0].Add("3");
...
Service.sendList(list.ToArray());

或者,更簡潔地說,像這樣:

var list = new List<List<string>>();
list.Add(new List<string>(new string[] { "february", "3", "5" }));
...
Service.sendList(list.ToArray());

當然,您始終可以按以下方式解析JavaScript中的整數:

parseInt(data[0][1], 10); // parses "2" into 2 (base 10)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM