1、导入org.json.jar包到apache-jmeter/lib/ext/目录下
2、例如响应信息是
{\"TotalCount\": 10,\"ItemList\": [{\"Id\": 7,\"Title\": \"早安分享\",},{\"Id\": 3,\"Title\": \"晚安分享\",}]}
3、beanshell代码
import org.json.JSONObject;
import org.json.JSONArray;
boolean flag = false;
String title;
int id;
String response = prev.getResponseDataAsString();; //获取请求返回值。注意此处只能获取到String类型;
JSONObject jsonObject = new JSONObject(response);//将String类型的返回值构造成JSONObject对象
JSONArray itemListArrays = jsonObject.getJSONArray("ItemList");//将json的[]中的数组转换为JSONArray数组
int len = itemListArrays.length();//获取数组长度
for (int i = 0; i < len; i++) {
JSONObject jsonObjectI = itemListArrays.getJSONObject(i);
title = jsonObjectI.getString("Title");
id = jsonObjectI.getInt("I