0

部分json对象如下,需要提取questionId并检查是否为数字:

{
    "rootProductQuestionId": "17",
    "questionAnswers": [ 
        {
            "question": "",
            "questionId": "17",
            "answer": ""
        }
    ],

    "productId": "8",
    "notes": ""
}
4

1 回答 1

3

您可以选择 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()
于 2017-11-27T09:23:48.387 回答