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

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

问题描述

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

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"
}]

想要解析以上响应,以在JSON提取器中将所有id都存储在一个字符串中,例如

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

3,1,6

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

My JSON Path expressions is like this:

$..id

但是我只有第一个id为3,与$.[0].id的结果相同 在BeanShell PostProcessor中检查结果. 如果我转到 http://jsonpath.com/ $ .. 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
]

推荐答案

如果您配置 JSON提取器,例如:

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

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

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提取器,提取字符串中一个键的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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