标签:eof closed path EDA net oat ToJson alt ret
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Predicate; import net.minidev.json.JSONArray; public class Test { public static String readjson(String json, String jsonPath) { try { Object value = JsonPath.read(json, jsonPath, new Predicate[0]); if (value instanceof Integer) { return value.toString(); }else if (value instanceof String) { return value.toString(); }else if (value instanceof Boolean) { return value.toString(); }else if (value instanceof JSONArray) { JSONArray arr = (JSONArray)value; if(!arr.isEmpty()){return arr.toJSONString();} return ""; }else if (value instanceof LinkedHashMap) { return value.toString(); }else if (value instanceof float) { return value.toString(); }else{ return value.toString(); } print("------------------------JsonPath详情value长度:"+value+"----------------------"); } catch(Exception e){ return "pathnotfound"; } } } //-------------------------------------------------------------------------------------------------------- public static void fun(){ String response_data=prev.getResponseDataAsString();//prev为JMeter预定义变量 String JsonPath="$.tts[0].text.length()"; print("------------------------JsonPath:"+JsonPath+"----------------------"); String result=Test.readjson(response_data,JsonPath); int resultToNum=Integer.parseInt(result); print("------------------------详情长度:"+result+"----------------------"); log.info("------------------------详情长度:"+result+"----------------------"); } fun();
标签:eof closed path EDA net oat ToJson alt ret
原文地址:https://www.cnblogs.com/a00ium/p/10363632.html