Serializing to JSON in jQuery
- by Herb Caudill
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).