JMeter:解析JSON和计数

时间:2013-07-12 17:42:02

标签: jmeter

我正在使用JMeter来测试Web应用程序。该应用程序返回如下所示的JSON:

{"type":"8","id":"2093638401"}
{"type":"9","id":"20843301"}
{"type":"14","id":"20564501"}

我需要根据类型进行计数。

我尝试使用正则表达式提取器添加foreach控制器,但我不确定我是否已正确完成:

  • 仅适用于:主要样本
  • 要检查的响应字段:正文
  • 参考名称:match_type
  • 正则表达式:“type”:“(\ d)”
  • 模板:$ 1 $
  • 比赛号码:-1

我是JMeter的新手,所以我不确定我是否正确地做了这些。

由于

1 个答案:

答案 0 :(得分:0)

如果你想在单个采样器中对type和id进行操作,我认为简单的正则表达式和ForEach控制器是不够的。您必须编写两个正则表达式提取器,然后使用BSF processor(javascript或beanshell)控制器来提取这两个值并将它们导出到jmeter变量。以下类型的东西

- First Request
  - Regex extractor for type
  - Regex extractor for id
  - BSF processor (to initialize the loopcount=0 and the total_matches of matches that you found)
- while controller (loopcount < total_matches)
  - BSF processor 
     - export/set current_type = type_$loopcount
     - export/set current_id = id_$loopcount
     - increment loopcount
  - USE current_type and current_id in whatever sampler you like

==更新==

这个http://goo.gl/w3u1r教程详细描述了如何去做。