json - 在 Jmeter 中提取值
问题描述
我的场景涉及回答一个包含 50 多个问题的测验。点击问题端点会给我一个测验中的所有问题 ID,但每个 ID 至少有 5 个答案 ID,我需要遍历 50 多个问题并为每个问题选择至少一个答案 ID 以提交答案。
目前,我在 Jmet3er 中有以下内容
获取请求 - 获取所有问题 ID 和所有答案 ID
Json Extractor 1 - 存储所有问题 ID
Json Extractor 2 - 仅存储第一个问题的 1 个答案 ID
ForEach 控制器 - 遍历问题 ID 计数器 - n
提交答案请求 - 对于每个问题,但答案相同
请指教
谢谢
解决方案
您可以使用JsonPath 过滤器运算符来映射问题的答案
例如,给定这个 JSON:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
您可以通过此 JsonPath 查询拥有所有 4 个作者:
$..author
但是,如果您想确定The Lord of the Rings
书籍的作者,您可以使用前面提到的过滤器表达式,例如:
$..[?(@.title == 'The Lord of the Rings')].author
推荐阅读
- sql - 创建动态数组
- javascript - 如何解决 POST 400 {bad Request} ReactJS
- tosca - 如何验证没有内部文本的 tosca 中的链接文本值
- django - Django 模型转换为 HTML。然后,HTML转PDF
- webassembly - 将 libsoxr 构建到 Webassembly 会导致函数签名不匹配错误
- laravel - 为同名但模型不同的表单字段添加验证规则
- sap-cloud-sdk - 使用 S4HANA 可扩展服务 - VDM 方法或其他方式
- python - 如何从单词文件的几行中拆分每个单词?(Python)
- scala - 执行方法,其中方法名称在列表中
- angular - 在 Anuglar 中的刷新调用后无法重试相同的请求