My current project involves exploring the usage of JSON in conjunction with jQuery and MVC2. My goal is to generate JSON data for an AJAX post request to my controller. I have created an array using the following function:
function getArguments() {
var argument1 = urlarray.slice(2, 3);
var argument2 = urlarray.slice(3, 4);
var argument3 = urlarray.slice(4, 5);
var argument4 = urlarray.slice(5);
return { Argument1: argument1, Argument2: argument2, Argument3: argument3, Argument4: argument4 }
}
To convert this data into a JSON format, I am utilizing json2.js as follows:
var data = getArguments();
var json = JSON.stringify(data);
Upon examining the generated JSON output, it appears like this:
{"Argument1":["16"],"Argument2":["2"],"Argument3":["True"]}
Although this seems to be valid JSON, the presence of square brackets within the values is confusing me. As far as I know, square brackets typically indicate an array. Can anyone shed some light on why json2.js and its stringify method are including these brackets? It feels like there's something simple that I'm missing here.