【发布时间】:2019-11-02 10:41:44
【问题描述】:
我有一个返回以下结果的 API:
{"success":true,
"error":null,
"data": {"EmpId":444,"ProfileNo":0,"ProfileName":"xya","Rank":0,"ScoreValue":0,"CompanyEmpID":"A25842"}}
我需要将上面的 JSON 传递给 JSR223 断言以单独验证所有输出值。我设法编写了以下脚本
import groovy.json.JsonSlurper;
JsonSlurper JSON = new JsonSlurper ();
def expected = new groovy.json.JsonSlurper().parseText(vars.get('Employee
data'))
def actual = new
groovy.json.JsonSlurper().parse(prev.getResponseData({"success":true,
"error":null,
"data":
{"EmpId":444,
"ProfileNo":0,
"ProfileName":"xya","Rank":0,"ScoreValue":0,"CompanyEmpID":"A25842"}})
if (expected != actual) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Mismatch between expected and actual
JSON')
}
但它失败了。我收到如下错误:
断言错误:真 断言失败:假 断言失败消息:javax.script.ScriptException:org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败: Script20.groovy: 10: 期待 '}',在第 10 行第 81 列找到':'。 rev.getResponseData({"成功":true, ^
1 个错误
【问题讨论】: