beanshell利用fastjson断言json数据

柔情痞子 提交于 2019-12-16 20:04:44

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");

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!