1、导入fastjson.jar包到apache-jmeter/lib/ext/目录下
2、例如返回数据为如下json格式数据
{
"code": 0,
"data": {
"userInfo": {
"id": 779025,
"wechatName": "David"
},
"classics": false
},
"success": true
}
3、beanshell代码
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
//String resp=new String(ResponseData);
//获取响应信息
String resp = prev.getResponseDataAsString();
//转为JSONObject对象
JSONObject jsonObject=JSON.parseObject(resp);
//获取string类型值
String wechatName = jsonObject.getJSONObject("data").getJSONObject("userInfo").getString("wechatName");
//获取Long类型值
Long id_Long = jsonObject.getJSONObject("data").getJSONObject("userInfo").getLong("id");
//获取int类型值
int id_int = jsonObject.getJSONObject("data").getJSONObject("userInfo").getInteger("id");
来源:CSDN
作者:萌翻天
链接:https://blog.csdn.net/qq_40308101/article/details/103568000