英文:
Jmeter: how to extract json object of array from repsosne using beanshell post process
问题
I need to get the data which is under seq array 我需要获取位于seq数组下的数据。
英文:
Im new to jmeter and wanted to extract the array data from json object
i have a Json as below
{
"error": false,
"data": {
"seq": [
"71128dfa",
"cbfda925",
"9d9bfa68",
"0ca86cf2",
"8bc3cfa7",
"4ea9aee3"
],
"request_id": "1db799cf-8f2b-4982-a23e-b2fb95b609b9"
}
}
i need to get the data which is under seq array
答案1
得分: 1
你可以使用Json提取器来提取它
你需要传递JSON路径表达式来检索它
英文:
You can use Json Extractor to extract it
you need to pass the json path expression to retrieve it
答案2
得分: 0
自 JMeter 3.1 版本起,建议使用 JSR223 测试元素和 Groovy 语言进行脚本编写,因此我建议切换到 JSR223 后置处理器。
如果您想提取位于 seq
属性下的 JSON 数组,可以使用以下代码进行提取:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def seq = response.data.seq
vars.put('seq', new groovy.json.JsonBuilder(seq).toString())
您可以在需要的地方使用 ${seq}
引用提取的值。
演示:
更多信息:
英文:
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Grooovy language for scripting so I would recommend switching to JSR223 Post-Processor
If you want the JSON Array which lives under seq
attribute you can extract it using the following code:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def seq = response.data.seq
vars.put('seq', new groovy.json.JsonBuilder(seq).toString())
You will be able to refer the extracted value as ${seq}
where required.
Demo:
More information:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论