jQuery's .ajax not putting indexs in arrays
Hi, I have to send a several arrays as query parameters to a Spring server.
The payload I'm trying to send is this:
- {"activeQuestion":"551","categories":["129","129","128"],"categoryAnswers":["487","489","488"]}
Basically, it's an object that contains 1 property that contains a number, and 2 arrays that contain numbers.
The problem is that as request parameters, they appear like this (taken from firebug):
| activeQuestion |
551 |
| categories[] |
129 |
| categories[] |
128 |
| categoryAnswers[] |
487 |
| categoryAnswers[] |
488 |
Now, if I were to wrap the nunbers into objects, jQuery actually puts the indexes in. Here's what the json looks like when they are wrapped:
- {"activeQuestion":"551","studentCategoryAnswers":[],"categories":[{"category":"129"},{"category":"128"},{"category":"128"}],"categoryAnswers":[{"categoryAnswer":"487"},{"categoryAnswer":"486"},{"categoryAnswer":"488"}]}
And here's what the request parameters look like:
| activeQuestion |
551 |
| categories[0][category] |
129 |
| categories[1][category] |
128 |
| categories[2][category] |
128 |
| categoryAnswers[0][categoryAnswer] |
487 |
| categoryAnswers[1][categoryAnswer] |
486 |
| categoryAnswers[2][categoryAnswer] |
488 |
While this gets me the indexes, this is not the format that the Spring server wants (obviously). Nor is this the correct way to structure the data. This is overkill and is going to make the server do more work than it really should.
Is there any way to get the indexes with the original, simpler JSON?
Please help. This kind of thing is driving me nuts. I hate working with primitive stuff and having to do a lot of redundancy just to get data transmitted. I just want it to work with the domain object model on the server... but there's always these weird exceptions that make that impossible. It's amazing that in 2010, we are still working in basic numbers and arrays and having to take apart and put together data at a primitive level.... sigh