首页 > 解决方案 > 如何在 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();
                    }
                }

谢谢,

标签: phpandroidexceptionyii2android-volley

解决方案


推荐阅读