JMeter JSON提取器通过条件获取价值 [英] JMeter JSON Extractor to get value by condition
本文介绍了JMeter JSON提取器通过条件获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到这样的JSON
字符串:
[{"id":123,"name":"XX","default":false,"type":"other"},{"id":789,"name":"ZZ","default":false,"type":"first"}]
我想获取id
,其中名称为ZZ
,因此提取的值应为789
.
我尝试使用以下JSON表达式:
I would like to get id
, where name is ZZ
, so extracted value should be 789
.
I tried with this JSON expression:
$.id[?(@.name=='ZZ')]
我也尝试过使用正则表达式:
I tried with regular expression too:
{"id":(.+?),"name":"ZZ","default":false
,
我的正则表达式解决方案无法正常工作,因为有相似的name
值,例如ZZ
和ZZ (XYZ)
.
My regular expression solution isn't working, because there are similar name
values, like ZZ
and ZZ (XYZ)
.
推荐答案
您很近,使用JSON提取器,您需要找到ZZ,然后获取对象返回的ID,请使用以下表达式:
You were close, with JSON extractor you need to find ZZ and then get the id of the object return, use the following expression:
[?(@.name == 'ZZ')].id
这篇关于JMeter JSON提取器通过条件获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文