我的json回复
{
"planList": [
{
"planCode": "xx",
"statusCode": "0"
},
{
"planCode": "yy",
"statusCode": "0",
"statusMessage": "Success"
},
{
"planCode": "zz",
"statusCode": "0"
}
]
}
现在我想计算plancode
的出现次数。
答案 0 :(得分:0)
def json = new groovy.json.JsonSlurper().parseText(""" {
"planList": [
{
"planCode": "xx",
"statusCode": "0"
},
{
"planCode": "yy",
"statusCode": "0",
"statusMessage": "Success"
},
{
"planCode": "zz",
"statusCode": "0"
}
]
}
""")
println json.planList*.planCode // all planCodes
println json.planList*.planCode.size() // all planCodes' count
println json.planList*.planCode.unique() // uniq planCodes
println json.planList*.planCode.unique().size() // uniq planCodes's count