Arrays 如何通过GRAILS构建下面提到的JSOn数组?

Arrays 如何通过GRAILS构建下面提到的JSOn数组?,arrays,json,grails,Arrays,Json,Grails,如何使用grails生成JSON数组,如下所示: {"paymentRequestlist":[{"sourceAccountNo":"555555555555555","sourceBankCode":"GLBBNPKA","destinationBankCode":"GLBBNPKA","destinationBankAccountNo":"123456789111111","corporateName":"","amount":14000,"remarks":"","narrationOn

如何使用grails生成JSON数组,如下所示:

{"paymentRequestlist":[{"sourceAccountNo":"555555555555555","sourceBankCode":"GLBBNPKA","destinationBankCode":"GLBBNPKA","destinationBankAccountNo":"123456789111111","corporateName":"","amount":14000,"remarks":"","narrationOne":"fund transfer initiated by maker 1","narrationTwo":"","uniqueId":"ESW-COR:1405491430740"},{"sourceAccountNo":"555555555555555","sourceBankCode":"GLBBNPKA","destinationBankCode":"GLBBNPKA","destinationBankAccountNo":"123456789111111","corporateName":"","amount":13000,"remarks":"","narrationOne":"fund transfer initiated by maker 1","narrationTwo":"","uniqueId":"ESW-COR:1405491430740"}]}
JSONArray postParamsArray = new JSONArray()

JSONObject postParams = new JSONObject();
            postParams.put('sourceAccountNo',fundTransfer.fromAccount.accountNumber);
            postParams.put('sourceBankCode',fundTransfer.fromAccount.bank.bankCode);
            postParams.put('destinationBankCode',fundTransfer.toAccount.bank.bankCode);
            postParams.put('destinationBankAccountNo',fundTransfer.toAccount.accountNumber);
            postParams.put('corporateName','');
            postParams.put('amount',fundTransfer.amount);
            postParams.put('remarks','');
            postParams.put('narrationOne',fundTransfer.note);
            postParams.put('narrationTwo','');
            postParams.put('uniqueId',fundTransfer.uniqueId);

 postParamsArray.add(postParams);
到目前为止,我尝试使用grails.converters.JSON构建一个数组,如下所示:

{"paymentRequestlist":[{"sourceAccountNo":"555555555555555","sourceBankCode":"GLBBNPKA","destinationBankCode":"GLBBNPKA","destinationBankAccountNo":"123456789111111","corporateName":"","amount":14000,"remarks":"","narrationOne":"fund transfer initiated by maker 1","narrationTwo":"","uniqueId":"ESW-COR:1405491430740"},{"sourceAccountNo":"555555555555555","sourceBankCode":"GLBBNPKA","destinationBankCode":"GLBBNPKA","destinationBankAccountNo":"123456789111111","corporateName":"","amount":13000,"remarks":"","narrationOne":"fund transfer initiated by maker 1","narrationTwo":"","uniqueId":"ESW-COR:1405491430740"}]}
JSONArray postParamsArray = new JSONArray()

JSONObject postParams = new JSONObject();
            postParams.put('sourceAccountNo',fundTransfer.fromAccount.accountNumber);
            postParams.put('sourceBankCode',fundTransfer.fromAccount.bank.bankCode);
            postParams.put('destinationBankCode',fundTransfer.toAccount.bank.bankCode);
            postParams.put('destinationBankAccountNo',fundTransfer.toAccount.accountNumber);
            postParams.put('corporateName','');
            postParams.put('amount',fundTransfer.amount);
            postParams.put('remarks','');
            postParams.put('narrationOne',fundTransfer.note);
            postParams.put('narrationTwo','');
            postParams.put('uniqueId',fundTransfer.uniqueId);

 postParamsArray.add(postParams);

另外,我对grails完全陌生!!任何建议都会有很大帮助

用以下内容完成您的代码:

JSONObject completeJson = new JSONObject()
completeJson.put("paymentRequestlist",postParamsArray)

println completeJson as JSON
您可以创建一个映射(更简单)并将其转换为JSON

简单(未测试)示例