如下所示,json对象的一部分需要提取questionId
并检查它是否为数字:
{
"rootProductQuestionId": "17",
"questionAnswers": [
{
"question": "",
"questionId": "17",
"answer": ""
}
],
"productId": "8",
"notes": ""
}
答案 0 :(得分:2)
您可以选择isNumber()检查,例如:
import groovy.json.jsonSlurper
def jsonSlurper = new JsonSlurper()
def json = jsonSlurper.parseText('{"rootProductQuestionId":"17","questionAnswers":[{"question":"","questionId":"17","answer":""}],"productId":"8","notes":""}')
return json.questionAnswers.questionId[0].isNumber()