Android JSONObject retrieve value



嘿,这是我得到的json响应 { "状态":200, "留言":"成功" }这是我得到的错误org.json.JSONException: 没有状态值这就是我提取值的方式

 try {
        JSONObject jObject = new JSONObject(dataSent);
                if(jObject.getInt("status") == 200){
                    isProfileCreated = true;
                    return isProfileCreated;
                }else{
                    isProfileCreated = false;
                    return isProfileCreated;
                }
    }catch (JSONException e) {
        e.printStackTrace();
        return false;
    }

是什么原因导致此问题,它在此特定行上崩溃

if(jObject.getInt("status") == 200){

您可以检查您的 json 是否包含键"状态":

 if (json.has("status")) {
// json contains "status" key
 }

最新更新