JMeter JSON Extractor,提取字符串中一个键的所有值 [英] JMeter JSON Extractor, extract all values of one key in a string

查看:24
本文介绍了JMeter JSON Extractor,提取字符串中一个键的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Apache JMeter ver 3.2 r1790745(最新版)测试 JSON Web 服务,响应如下:

[ {身份证":3,"描述": "返回",名称":返回"}, {身份证":1,描述":正面",名称":前面"}, {身份证":6,"描述": "左",名称":左"}]

想在JSON Extractor中解析上面的响应以获取一个字符串中的所有id,例如

3,1,6

我的 JSON Path 表达式是这样的:

$..id

但我只得到了第一个 id,即 3,结果与 $.[0].id 相同在 BeanShell PostProcessor 中检查结果.如果我去

您将获得所需的值 ${foo_ALL}

<小时>

我不认为使用 Beanshell 是检查 JMeter 变量值的最佳方法,今后我建议使用 调试采样器,请参阅如何调试您的 Apache JMeter 脚本以获取更多详细信息.

Using Apache JMeter ver 3.2 r1790745 (the latest) to test a JSON Web Service, the response is like:

[ {
   "id" : 3,
   "description" : "Back",
   "name" : "back"
}, {
   "id" : 1,
   "description" : "Front",
   "name" : "front"
}, {
   "id" : 6,
   "description" : "Left",
   "name" : "left"
}]

Want to parse the above response to get all ids in one string in JSON Extractor, like

3,1,6

My JSON Path expressions is like this:

$..id

But I got only the 1st id which is 3, the same result as $.[0].id Checking the result in a BeanShell PostProcessor. If I go to http://jsonpath.com/ $..id does give me

[
  3,
  1,
  6
]

解决方案

If you configure your JSON Extractor like:

You will get the required value as ${foo_ALL}


I don't think using Beanshell is the best way to check JMeter Variable value, going forward I would suggest using Debug Sampler instead, see How to Debug your Apache JMeter Script for more details.

这篇关于JMeter JSON Extractor,提取字符串中一个键的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆