脚本:
import org.json.*;
import java.util.Arrays;
import org.apache.jmeter.assertions;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.assertions.AssertionResult;
import org.json.simple.JSONArray;
import org.json.simple.JSONException;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
String jsonString = prev.getResponseDataAsString();//get response
JSONObject responseJson = new JSONObject(jsonString);//change to Json
String prompt = responseJson.getString("prompt");//get the value of prompt
if (!prompt.contains("错误")) {
Failure =false;
FailureMessage = "失败";
} else {
Failure = true;
FailureMessage = "成功";
}
返回错误:BeanShell断言 : org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.json.*; import java.util.Arrays; import org.apache.jmeter.assertions; . . . '' : Typed variable declaration : Class: JSONObject not found in namespace