0

My C# application provides the data and send it to a WebService, like this :

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

and the way I retrieve this data through a WebService in a Javascript function is like this :

 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
 }

Now, I need my var data like this :

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

How I need to send it from C# to the WebService in order to have at the end a var data like just above ?

Thanks for your help !

1
  • 1
    try using an object list: List<object> list = new List<object>(); list.Add(new object[]{"january", 2, 3}); //... Commented May 27, 2015 at 14:19

1 Answer 1

1

You will need to send the data as a two-dimensional array.

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());

Or, more succinctly, like this:

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

And of course, you can always parse the integers in JavaScript as follows:

parseInt(data[0][1], 10); // parses "2" into 2 (base 10)
Sign up to request clarification or add additional context in comments.

1 Comment

@Johny_Rose Thanks for your help ! I ll try that soon ! I have an example of what I need in var data : jsfiddle.net/anh2gs7w/2 Do you really think your method in order to send data like above will work ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.