gpt4 book ai didi

regex - jMeter RegEx JSON响应

转载 作者:行者123 更新时间:2023-12-04 09:06:59 25 4
gpt4 key购买 nike

我已经阅读了一些有关jMeter RegEx提取的教程,但是没有用。我正在使用jMeter 2.7。

我有这个JSON:

{"address":{"id":26,"user_id":1,"genre":"billing","first_name":"testFN1","last_name":"testLN1","company":null,"street1":null,"street2":null,"city":null,"state":"DC","zip":null,"country":null,"country_iso2":null,"phone1":"32432424322","phone2":null}}

这个RegEx Extractor:“id”:(。+?),这是jMeter的屏幕截图

对于提取,我得到 $new_address_id = 2 ,而不是 26 。有任何想法吗?

更新2012年6月26日:

感谢Cylian的建议。这是非常有帮助的。我最终将其更改为: "id":(\d+)

我还在JMX文件中找到了一个替换项
<stringProp name="RegexExtractor.regex">&quot;id&quot;:(.+?,)</stringProp>

并替换为
<stringProp name="RegexExtractor.regex">&quot;id&quot;:(\d+)</stringProp>

很快就解决了。谢谢!

最佳答案

我建议你看看:

http://jmeter-plugins.org/wiki/JSONPathExtractor/

本节(JSON实用程序(JSON路径声明,JSON路径提取器,JSON格式化程序))特别适用于这种情况。这些是我公司开发的jmeter工具集,非常有用。

让我们以您的情况为例。测试用例如下所示:

因此,虚拟样本会返回响应,就像您指定的那样:

{"address":{"id":26,"user_id":1,"genre":"billing","first_name":"testFN1","last_name":"testLN1","company":null,"street1":null,"street2":null,"city":null,"state":"DC","zip":null,"country":null,"country_iso2":null,"phone1":"32432424322","phone2":null}}

JSON提取非常简单:
$.address.id

而且,您无需花哨的正则表达式。结果是26(这是我在调试采样器中看到的)。

从评论中的问题更新:

如果您要获取值列表,即:
{"address":[{"id":26,"user_id":1,"genre":"billing","first_name":"testFN1","last_name":"testLN1","company":null,"street1":null,"street2":null,"city":null,"state":"DC","zip":null,"country":null,"country_iso2":null,"phone1":"32432424322","phone2":null}, {"id":6,"user_id":1,"genre":"billing","first_name":"testFN1","last_name":"testLN1","company":null,"street1":null,"street2":null,"city":null,"state":"DC","zip":null,"country":null,"country_iso2":null,"phone1":"32432424322","phone2":null}]}

具有2个address-es的列表,其中1个ID为26,另一个ID为6。JsonPath $.address.id应该返回这两个ID。我刚刚看到了采样器源代码,无法获得计数,但是您可以通过向示例中添加另一个后处理器(即 BSF Sampler)并添加以下代码来实现:
vars.put("ADDRESS_COUNT", "${__javaScript('${add}'.split('\,').length,)}".toString());

其中 ${add}是存储 $.address.id结果的任何变量。

关于regex - jMeter RegEx JSON响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11060483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com