Serializing to JSON in jQuery

Posted by Herb Caudill on Stack Overflow See other posts from Stack Overflow or by Herb Caudill
Published on 2008-10-10T15:29:56Z Indexed on 2010/05/18 9:11 UTC
Read the original article Hit count: 136

Filed under:
|
|

I know how to serialize an object to JSON in ASP.NET Ajax, but I'm trying to do things on the client in a less Microsoft-specific way. I'm using jQuery. Is there a "standard" way to do this?

My specific situation: I have an array defined something like this:

var countries = new Array();
countries[0] = 'ga';
countries[1] = 'cd';
...

and I need to turn this into a string to pass to $.ajax() like this:

$.ajax({
    type: "POST",
    url: "Concessions.aspx/GetConcessions",
    data: "{'countries':['ga','cd']}",
...

Edit (clarification)

I realize there are a number of JSON libraries out there, but I'd like to avoid introducing a new dependency (if I'm going to do that, I might as well use ASP.NET Ajax's built-in JSON serializer).

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON