2

I need to pass an array from JavaScript to a page method in C#. I have tried using a parameter in the C# method of IList and also a string[] array. Both ways throw an exception "cannot convert an object of type system.string to xxx", where xxx is the parameter type in the C# method. I am passing the object from jQuery as a json object, and looks like it is coming through properly. Here is what it looks like:

{"testNumbers":"5555555555,3333333333,4444444444"}

What am I doing wrong here?

EDIT: C# Code:

[WebMethod()]
public static void ProcessAction(string[] testNumbers)
{
    var dataProvider = new DataProvider();
    dataProvider.ProcessAction(testNumbers);
}
0

3 Answers 3

10

Hmm, two things:

  1. JSON arrays have square brackets around them
  2. JSON numbers aren't quoted.

Try this instead:

{"testNumbers": [5555555555,3333333333,4444444444]}
Sign up to request clarification or add additional context in comments.

Comments

3

You need to use one of the .NET JSON Deserializers:

http://msdn.microsoft.com/en-us/library/bb299886.aspx

Comments

0
{"testNumbers":["5555555555","3333333333","4444444444"]} 

should i think do the trick along with a deserialiser. see http://www.json.org/ which has a great graphical representation of the json syntax.

Comments

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.