1、把fastjson-1.2.31.jar的jar包,放到 jmeter的lib路径下面,然后重启jmeter
2、jmeter中的请求返回如下:
在 beanshell中如下:
import org.apache.jmeter.samplers.SampleResult; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONPath; SampleResult result = ctx.getPreviousResult(); //获取返回数据 String response_data = prev.getResponseDataAsString(); JSONObject data_obj= JSON.parseObject(response_data); log.info("-----data_obj---------" + data_obj.toString()); log.info("++++++++++Response++++"+ response_data); String Provincelist_str = data_obj.getString("baseCus"); log.info("-----Provincelist_str---------"+ Provincelist_str); String birthday = data_obj.getString("birthday"); log.info("-----birthday---------"+ birthday); int certTypeId = JSONPath.eval(data_obj,"$.certList[0].certTypeId"); log.info("-----cifCusId---------"+ certTypeId);
这里要注意,获取的 数据的类型,string int 等