Jmeter 如何使用jsonpath从json中获取多个元素?
我有一个简单的JSON,我想得到两个属性:Jmeter 如何使用jsonpath从json中获取多个元素?,jmeter,jsonpath,Jmeter,Jsonpath,我有一个简单的JSON,我想得到两个属性: 核心和匹配并验证是否核心:真和匹配:真 { "lockVersion" : 1, "updatedBy" : "jan", "updatedOn" : "2016-09-25T11:21:45Z", "id" : 964, "title" : "Corporate Numeric", "description" : null, "descType" : 31084140,
核心
和匹配
并验证是否核心:真
和匹配:真
{
"lockVersion"
: 1,
"updatedBy" : "jan",
"updatedOn" : "2016-09-25T11:21:45Z",
"id" : 964,
"title" : "Corporate Numeric",
"description" : null,
"descType" : 31084140,
"descValueType" : 31084136,
"defaultSourceOfVerification" : "Source",
"core" : true,
"matching" : true,
"anything" :
[
],
"authorized"
:
[
1
]
}
是否可以使用AND运算符执行此操作,或者我必须执行两步操作以提取一个集合,然后再次过滤以获得最终结果?
我要用jp@gc-JSON路径断言。有关JSON路径断言插件,请参阅
因此,使用Core JMeter,您可以像这样使用作用域“JMeter Variable”:
您应该能够使用BeanShell断言和内置JSON解析器来实现这一点
import net.minidev.json.parser.JSONParser;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;
try {
// Use JSONParser to parse the JSON
JSONParser parser = new JSONParser(JSONParser.ACCEPT_NON_QUOTE|JSONParser.ACCEPT_SIMPLE_QUOTE);
JSONObject rootObject = (JSONObject) parser.parse(prev.getResponseDataAsString());
if ( rootObject.get("matching") && rootObject.get("core") ) {
Failure=false;
}
else {
Failure=true;
}
}
catch ( Exception ex) {
log.info("Exception.." + ex);
Failure=true;
}
按如下方式配置JSON路径断言:
- JSON路径:
[?($.core==true&&$.matching==true)]
- 勾选
框根据预期值进行验证
- 预期值:
[]
- 勾选
框反转断言