2013-07-12 60 views
0

我正在使用JMeter测试Web应用程序。该应用程序返回JSON,如下所示:JMeter:解析JSON和计数

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

我需要根据类型获取计数。

我试图用正则表达式提取添加的foreach控制器,但是我不知道我已经正确的:

  • 适用于:主要样本只有
  • 响应现场检查:身体
  • 参考名称:MATCH_TYPE
  • 正则表达式: “类型”: “(\ d)”
  • 模板:$ 1 $
  • 不匹配:-1

Im新的JMeter所以我不知道我是否正确地做了这些。

感谢

+0

你能澄清你的意思吗?“我需要得到一个基于类型的计数。” ? –

+0

这不是真的JSON。它实际上是一个JSON数组(例如'[{“type”:“8”,“id”:“23324”},{“type”:“42”,“id”:“22224”}]')? – fncomp

回答

0

如果你想在这两个类型和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教程描述的东西究竟是如何去做。