Jmeter 通过json Extracted 来获取 指定的值的id
在没有 精确或模糊查询的接口时可以使用jmeter 获取指定的值的ID
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import java.lang.String ; String getTargetName="iphone632g"; //判读相应结果中是否包含指定值:iphone632g boolean containsCategory=prev.getResponseDataAsString().contains(getTargetName); vars.putObject("containsCategory",containsCategory); if(containsCategory){ String [] categoryNameSplit="${categoryName_ALL}".split(",") ; String [] categoryIDSplit = "${categoryID_ALL}".split(","); for (int i=0 ; i<categoryNameSplit.length ;i++ ) { //假如找到指定的分类就将该分类的id put 到变量中去 ; if (categoryNameSplit[i].equals(getTargetName)) { log.info("i=========="+String.valueOf(i)); log.info("categoryIDSplit["+i+"]="+categoryIDSplit[i]); vars.put("categoryId",categoryIDSplit[i]); break ; } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
log.info("${__jexl2(${mobilePhone}*2+4,)}"); int a=${__jexl2(3*2+4,)}; Integer b=${__jexl2(3*2+4,)}+${__jexl2(3*2+4,)}; Integer b1=${__jexl2(${pim_interfaceType}+${pim_interfaceType})}; log.info("b1=="+b1); //${__jexl2(,)}+${__jexl2(,)} 返回结果可以是String 类型 或者 Integer 类型; String value ="${__jexl2(3*2+4,)}+${__jexl2(3*2+4,)}" ; log.info("value="+value); //String + Integer String value1 ="${__jexl2(3*2+4,)}"+${__jexl2(3*2+4,)} ; log.info("value1="+value1); Integer createOrderAfterlockQty3=Integer.parseInt("1")+${__jexl2(${quantity})}; log.info("xxxxxxxxxxxxxxx=="+createOrderAfterlockQty3); String concatItemId="\""+"${itemId_all}".replace(",", "\",\"")+"\"" ; log.info("concatItemId="+concatItemId);