json封装类

public class JsonUtils {
    //获取json内置某一特定数据数据
    public String getInternalName(JSONObject jo){
        String internalName = "";
        try {//先获取反馈中的result这个一个内部JSON对象 (result是根据json命名)
            JSONObject internalJSON = jo.getJSONObject("result");
            //再根据键名查找键值
            internalName = internalJSON.getString("city") ;
        }catch (Exception e){
            e.printStackTrace();
        }
        return internalName;
    }
    //获取json某一特定数据数据
    public String getName(JSONObject jo){
        String name = "";
        try {
            name= jo.getString("code") ;//code根据需求可变
        }catch (Exception e){
            e.printStackTrace();
        }
        return name;
    }
    //用jsonpath处理json,获取内置result中特定键值并进行比对
    public boolean isResponseCorrect(JSONObject jo, String checkpoint, String passValue){
        ReadContext context = JsonPath.parse(jo);
        JSONArray result = context.read("$.result.."+checkpoint);  //该句比对内置json
        String resultString = result.get(0).toString();
        if(resultString.equals(passValue)){
            return true;
        }else{
            return false;
        }
    }
    //用jsonpath处理json,获取result中特定键值并进行比对
    public boolean isResponseCode(JSONObject jo, String checkpoint,String passValue){ //用jsonpath处理json,获取result中特定键值

        String checkName= jo.getString(checkpoint);
        if(checkName.equals(passValue)){
            return true;
        }else{
            return false;
        }
    }

}