Android JSONObject检索值
嘿,这是我得到的json响应 { “地位”:200, “消息”:“成功” } 这就是我得到的错误 org.json.JSONException:状态没有值 这就是我提取值的方法Android JSONObject检索值,android,json,Android,Json,嘿,这是我得到的json响应 { “地位”:200, “消息”:“成功” } 这就是我得到的错误 org.json.JSONException:状态没有值 这就是我提取值的方法 try { JSONObject jObject = new JSONObject(dataSent); if(jObject.getInt("status") == 200){ isProfileCreated = true;
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是否包含键“status”: 尝试
jObject.optInt(“status”,-1)
而不是jObject.getInt(“status”)
if (json.has("status")) {
// json contains "status" key
}