Serializing to JSON in jQuery [duplicate]

I need to serialize an object to JSON. I’m using jQuery. Is there a “standard” way to do this?

My specific situation: I have an array defined as shown below:

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']}",
...

1
11

Leave a Comment