首页 > 解决方案 > Jmeter:如何使用 if 控制器检查 json 响应值是否为空

问题描述

如何使用jmeter中的if控制器检查空响应值?

我的 json 响应看起来像:{ userID: null }

在 Jmeter 中使用 if 控制器,我想验证,userID 为 null

我正在使用: "${userID}"==null 但这不起作用。

标签: jmeter

解决方案


您发布的内容看起来不像是有效的 JSON,您可以使用JSONLint服务进行仔细检查

如果您的响应是有效的 JSON,例如,它看起来像:

{
  "userID": null
}

您可以使用以下__groovy() 函数作为 If Controller 的条件:

${__groovy(new groovy.json.JsonSlurper().parse(ctx.getPreviousResult().getResponseData()).userID==null,)}

在此处输入图像描述

更多信息:


推荐阅读