简体   繁体   English

在Jmeter中提取数组中的json

[英]Extract json in an array in Jmeter

How do I extract the json object name from the below json data in Jmeter 如何从Jmeter中的以下json data中提取json对象name

[
:   {
:   :   "name":"x",
:   :   "age":"50",
:   :   "gender":"Female"
:   }
]

I am doing this $..name in the JsonPath Extractor which is giving me this in the variable I extracted to 我在JsonPath Extractor中执行这个$..name ,它在我提取的变量中给出了这个

name=["x"]

Is there a way I could just get name=x without the array format 有没有一种方法我可以得到没有数组格式的name=x

Or is there a way I can extract just the x from ["x"] ? 或者是有办法,我可以只提取x["x"]

Thanks 谢谢

Using this in a bean shell post processor worked 在bean shell post处理器中使用它可以工作

 String newName = vars.get("name"). replace([","").replace("]","").replace("\"","");
log.info("name is: " +newName);

which gives name is: x 给出的name is: x

You need to get name attribute from the first object in the array therefore you need to amend your JSON Path expression to look like $[0].name 您需要从数组中的第一个对象获取name属性,因此您需要将JSON Path表达式修改为$[0].name

References: 参考文献:

You may use 你可以用

 ${name_1} 

after getting the array with 获得数组后

$..name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM