php - 如何在 android studio (java) 中读取 PHP 异常?
问题描述
API 响应是 PHP 异常,如下所示:
{
"name": "Not Found",
"message": "The record is not found! [0x12]",
"code": 0,
"status": 404,
"type": "yii\\web\\NotFoundHttpException"
}
android studio中的日志E/Volley: [1270] BasicNetwork.performRequest: Unexpected response code 404 for http://localhost/api/v1/friend/mobile/123
此错误由 触发onErrorResponse(VolleyError error)
,因此不是 API 的响应。
-- 更新:这里是读取 JSON 的部分:
public void onResponse(JSONObject response) {
//Log.d(SENDMOBILE_TAG, response.toString());
dialog.dismiss();
try {
int status = response.getInt("status");
String message = response.getString("message");
if(status == 400) {
WebServiceUtils.showDialog(SendMobileActivity.this, "Error" ,message);
}else if(status == 201){
//WebServiceUtils.showDialog(SendMobileActivity.this, "Success" ,message);
Intent SendOtpActivity = new Intent(SendMobileActivity.this, SendOtpActivity.class);
startActivity(SendOtpActivity);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
谢谢,
解决方案
推荐阅读
- c - 从 2d char 数组指针中获取一个字符,该指针是 C 中结构指针的属性
- webpack - 如何使用 webpack-cli init 指定 webpack 配置文件名?
- javascript - jQuery如何找到存储在数组中的最后一个HTML元素
- virtocommerce - Virto Commerce 无法在 B2B 主题中添加报价功能
- python-3.x - Calling vcvarsall.bat in Python and using its env variables
- javascript - Connecting to Neo4j with Javascript (without drivers)
- sql - SQL Server 2008 Update multiple columns with loop or other method
- laravel - 试图在招摇 UI 中创建一个包含多个项目的数组
- powershell - 如何将bios serialmunber设置为用户密码
- python - 如何将文本文件中的最大值附加到列表中?