tags:

views:

135

answers:

2

Hi.

I am trying to use JSON.stringify() (from json2.js of json[dot]org ) to convert a JavaScript array to JSON string and to pass it to an asmx web method. I use jQuery AJAX.

The call reaches the web method where I take a List <Object> as parameter but I get an empty list there in debug mode.

My JSON string looks like well formed with all data , I even tried having single-quotes and double-quotes(escaped) around the 'names' of the JSON string. Please help.

+2  A: 
[WebMethod]
public void SomeMethod(List<object> param)
{
 ....
}

Will accept a JSON string that looks like this:

'{"param": ["xx", "zz", "yy"]}'

So , try something like this:

var data = JSON.stringify({param: myarray});
Sky Sanders
That's it :-). I was doing-JSON.stringify(myArr);But its wrapped in a member 'd'. So, this worked-JSON.stringify(myArr.d);
A: 

http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx

This link helped me out as well because I was looking to use a model for bringing the json data.

As an additional note, I was trying to use $.post(...), but I was not having any luck until I broke it out to a $.ajax call and specified the content-type.

malckier