【问题标题】:JMeter JSON Extractor, extract all values of one key in a stringJMeter JSON Extractor,提取字符串中一个键的所有值
【发布时间】:2017-05-10 12:36:12
【问题描述】:

使用Apache JMeter ver 3.2 r1790745(最新)测试一个JSON Web Service,响应如下:

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

想要解析上面的响应来获取JSON Extractor中一个字符串中的所有id,比如

3,1,6

我的 JSON 路径表达式是这样的:

$..id

但我只得到了第一个 id,即 3,结果与 $.[0].id 相同 在 BeanShell PostProcessor 中检查结果。 如果我去http://jsonpath.com/ $..id 确实给了我

[
  3,
  1,
  6
]

【问题讨论】:

  • 我收到了myvar=[3,1,6],正如你所提到的。我没有看到您的语法有任何错误。

标签: json jmeter extractor


【解决方案1】:

如果您将JSON Extractor 配置为:

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


我不认为使用 Beanshell 是检查 JMeter 变量值的最佳方法,今后我建议使用 Debug Sampler 代替,请参阅 How to Debug your Apache JMeter Script 了解更多详细信息。

【讨论】:

  • 值分隔用逗号代替,其他字符怎么用?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 2020-08-23
  • 1970-01-01
相关资源
最近更新 更多