如何使用Json将2维javascript数组传递给我的spring控制器?

时间:2015-06-09 15:41:59

标签: javascript jquery json spring spring-mvc

我正在尝试使用Json请求从Jquery传递一个2d数组到我的spring控制器。

这是我的javascript代码。 conditionValues(和其他参数)是一个多维数组的数组,例如conditionValues = [] []

$.getJSON("/SafeSiteLive/common/createTaskWizard/saveTask.json", {
            taskName: $("#taskName").val(),
            taskDescription: $("#taskDescription").val(),
            groupId: $("#approverGroupSelect").val(),
            version: selectedVersion,
            liveVersion: liveVersion,
            questions: questions,
            questionTypes: questionTypes,
            conditionValues: conditionValues,
            conditionTypes: conditionTypes,
            conditionPermits: conditionPermits
}, function (data){
   try {
       dialog.dialog("close");
       getGroups();
    } catch (e) {
        alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);
    }
});

然后在我的控制器中我有

@RequestMapping("common/createTaskWizard/saveTask.json")
public void saveTask(
        @RequestParam("taskName") String taskName,
        @RequestParam("taskDescription") String taskDescription,
        @RequestParam("groupId") int approversGroupId,
        @RequestParam("version") int version,
        @RequestParam("liveVersion") int liveVersion,
        @RequestParam("questions[]") String questions[],
        @RequestParam("questionTypes[]") String questionTypes[],
        @RequestParam("conditionValues[][]") String conditionValues[][],
        @RequestParam("conditionTypes[][]") String conditionType[][],
        @RequestParam("conditionPermits[][]") int conditionPermits[][]) {

        // rest of function

我可以通过在jQuery中正常传递并在@RequestParam中使用方括号接收它来简单地传递一维数组。这同样适用于2D阵列。有什么用吗?

在尝试传递json请求时,我从firebug得到的网络错误。

  

“NetworkError:400错误请求 - http://localhost:8080/SafeSiteLive/common/createTaskWizard/saveTask.json?taskName=Testing+voltages&taskDescription=Testing+voltages+with+generator+on&groupId=3&version=1&liveVersion=1&questions%5B%5D=Confirm+that+it+is+necessary+for+electrcial+equipment+to+be+live+while+testing%3F&questions%5B%5D=Would+de-energisation+create+hazards+for+others+(e.g.+de-energise+equipment+critical+to+process+safety%2C+warning+systems+etc)%3F&questions%5B%5D=If+%27Yes%27+to+1.2%2C+confirm+that+this+has+been+communicated+to+the+System+Owner%2FArea+Owner+and+adequate+precautions+implemented%3F&questions%5B%5D=Confirm+the+prospective+incident+energy+of+the+system+(cal%2Fcm2)&questionTypes%5B%5D=yesNoNA&questionTypes%5B%5D=yesNoNA&questionTypes%5B%5D=yesNoNA&questionTypes%5B%5D=textInput&conditionValues%5B0%5D%5B%5D=Yes&conditionValues%5B0%5D%5B%5D=NA&conditionValues%5B1%5D%5B%5D=Yes&conditionTypes%5B0%5D%5B%5D=equals&conditionTypes%5B0%5D%5B%5D=equals&conditionTypes%5B1%5D%5B%5D=equals&conditionTypes%5B2%5D%5B%5D=equals&conditionTypes%5B3%5D%5B%5D=equals&conditionPermits%5B0%5D%5B%5D=1&conditionPermits%5B0%5D%5B%5D=1&conditionPermits%5B1%5D%5B%5D=1&conditionPermits%5B2%5D%5B%5D=1&conditionPermits%5B3%5D%5B%5D=1”   saveTas ... [

0 个答案:

没有答案