在第一次系统调用失败后,我得到了这个json。
{
"header": {
"msgCode": "400",
"message": "Call failed!"
},
"body": {
"success": false,
"error_list": [
]
}
}
在每次系统调用失败后,我都会得到receipt_code,我必须将它附加到上面的json中。
{
"header": {
"msgCode": "400",
"message": "Call failed!"
},
"body": {
"success": false,
"error_list": [
{
"errors": [
{
"message": "Invalid receipt code!"
}
],
"receipt_code": "A-11277809" //here is receipt_code
}
]
}
}
对于所有后续调用,如果失败,则继续附加此。
{
"header": {
"msgCode": "400",
"message": "Call failed!"
},
"body": {
"success": false,
"error_list": [
{
"errors": [
{
"message": "Invalid receipt code!"
}
],
"receipt_code": "11111"
},
{
"errors": [
{
"message": "Invalid receipt code!"
}
],
"receipt_code": "1222"
}
]
}
}
Groovy如何做到这一点,有帮助吗?这是我代码
if(success!="true")
{
def receipt_code=receiptList[receiptFlag].receipt_code;
def error_list = []
def error ={
"errors": [
{
"message": "Invalid receipt code!"
}
],
"receipt_code": receipt_code //here is receipt_code
}
error_list.push(error)
error_list = JSON.stringify(error_list)
msg.put("error_list",error_list);
}
我无法使用上述代码添加
1条答案
按热度按时间8hhllhi21#
使用JsonSlurper
输出