我试图从JSON请求中获取TxnType
的值,同时嘲笑Soapui的响应。我想以不同的响应响应TxnType
的值。
{
"Request": {
"UserId": "user",
"TxnType": "fetch"
}
}
这是用固定的JSON
获取请求值的时髦脚本def json = """{
"Request": {
"UserId": "user",
"TxnType": "fetch"
}
}"""
def transactionType = new groovy.json.JsonSlurper().parseText(json).Request.TxnType
log.info "TxnType is : ${transactionType}"
您可以快速尝试 demo
如果要在模拟脚本中使用动态JSON,则可以在下面使用模拟脚本调度程序
def transactionType = new groovy.json.JsonSlurper().parseText(mockRequest.requestContent).Request.TxnType
log.info "TxnType is : ${transactionType}"
//选择"请求"
def requestBody = mockRequest.getRequestContent()
log.info "Request body: " + requestBody
//选择txntype值
def txnType = requestBody["TxnType"]
(或类似的东西)