【问题标题】:Android Studio, Volley I do not get a JSON responseAndroid Studio,Volley 我没有收到 JSON 响应
【发布时间】:2018-12-12 20:12:05
【问题描述】:

我已经使用 Jason Web 令牌构建了一个 laravel Rest API。现在我想制作一个将数据发送到 Web 服务的应用程序。在这里,我首先尝试验证自己(使用姓名电子邮件和密码),但我没有得到令牌作为答案。我也没有收到错误,没有任何反应。

private void sendAndRequestResponse() {
    try {
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("name", "ida");
        jsonBody.put("email", "ida@gmail.com");
        jsonBody.put("password", "secret");

        final String mRequestBody = jsonBody.toString();

        //RequestQueue initialized
        mRequestQueue = Volley.newRequestQueue(this);

        mJsonRequest = new JsonObjectRequest(
                Request.Method.POST, url, jsonBody,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d(TAG, response.toString());
                        answer.setText(response.toString());
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d(TAG, "Error: " + error.getMessage());
                    }
        });

        mRequestQueue.add(mJsonRequest);


    } catch (JSONException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

    标签: android post request android-volley response


    【解决方案1】:

    您需要启动请求队列才能进行请求调用。

    之后

    mRequestQueue.add(mJsonRequest);
    

    添加关注

    mRequestQueue.start();
    

    【讨论】:

    • 现在我没有得到我应该得到的值的答案,有没有办法过滤响应(我只想要一个特殊值而不是全部)
    • 您在 JSONObject 中得到了答案,因此您需要解析该 JSON 对象,然后才能获得答案
    猜你喜欢
    • 2015-03-18
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多