我的JsonBuilder出了点问题。我希望输出如下所示:
{
"appointmentCheckResult": [
{
"itexxmCode": "98765432",
" needAppointmentCheckFlag ": "Y"
},
{
"itemCode": "98765433",
"needAppointmentCheckFlag": "N"
}
]
}我得到的是:
{
"appointmentCheckResult": {
"xxx": [
{
"itemCode": "12345",
"needAppointmentCheckFlag": "Y"
},
{
"itemCode": "5678902",
"needAppointmentCheckFlag": "Y"
}
]
}
}代码如下所示:
import groovy.json.*
def json = new JsonBuilder()
def itemCode = ['12345', '5678902']
def needFlag = 'Y'
json.appointmentCheckResult{xxx([itemCode].transpose().collect {[itemCode:it[0], needAppointmentCheckFlag:needFlag]})}
println JsonOutput.prettyPrint(json.toString())如何去掉XXX和XXX前面的"{“?
发布于 2018-07-19 01:21:46
不知道如何在输出中获得Y和N,或者将itexxmCode作为关键字……但假设它们是预期输出中的拼写错误,则需要如下内容:
json {
appointmentCheckResult(
[itemCode].transpose().collect {
[itemCode: it[0], needAppointmentCheckFlag: needFlag]
}
)
}https://stackoverflow.com/questions/51403702
复制相似问题