2013-07-12 54 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教程描述的東西究竟是如何去做。