开发者

why does my json have square brackets?

开发者 https://www.devze.com 2023-03-19 02:12 出处:网络
I\'m investigating json with jquery and mvc2. I\'m trying to create some json for an ajax post to my controller. I have an array created by this function

I'm investigating json with jquery and mvc2. I'm trying to create some json for an ajax post to my controller. I have an array created by this 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 }
}

I'm using json2.js to create the json like so

var data = getArguments();
var json = JSON.stringify(data);

when I look at the json it looks like this:

{"Argument1":["16"],"Argument2":["2"],"Argument3":["True"]}

This looks开发者_StackOverflow中文版 like valid json, but I don't understand the square brackets. I thought that was an array... anyone know why json2.js and its stringify would be putting in these brackets?... feel like I'm missing something obvious here.


.slice() returns an array, even though you're slicing out only single values. Try something like:

var argument1 = urlarray[2];
var argument2 = urlarray[3];
etc...

which would return whatever's stored in those array slots (integer)?)

0

精彩评论

暂无评论...
验证码 换一张
取 消