凌空抽射。发送JSONObject作为参数

时间:2018-07-13 05:07:33

标签: java android android-volley

我已经搜索并查看了其他SO文章。但没有一个帮助。请帮助我找出问题所在。我所做的是我想从StringRequest更改为JsonObjectRequest

我收到此错误:

com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of 

我的密码

    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "http://"+employee.get_ip_address()+"/NextrackAndroid/authenticate.php";
    Log.d("TAG", "URL : "+ url);

    JSONObject obj = new JSONObject();
    try {
        obj.put("id", id.toString());
        obj.put("deviceID", deviceID.toString());
        Log.d("TAG", obj.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,url,obj,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d("TAG", "onResponse : " + response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("TAG", "onErrorResponse : " + error.toString());
                    error.printStackTrace();
                }
            }){
        /** Passing some request headers* */
        @Override
        public Map getHeaders() throws AuthFailureError {
            HashMap headers = new HashMap();
            headers.put("Content-Type", "application/json");
            return headers;
        }
    };
    queue.add(jsObjRequest);

1 个答案:

答案 0 :(得分:1)

  

com.android.volley.ParseError:org.json.JSONException:输入的结束符

的字符0

这不是您的附带问题。 当您的回复不是JSONObject时,此问题仍然存在。因此您的代码无法处理它。因为您已将JsonObjectRequest用作响应处理程序。

要解决此问题。

  • Postman上检查其响应,或向Web Service开发人员询问。
  • 您会发现Web服务的响应不是完美的JSON。
  • 然后要求Web服务开发人员解决此问题。
  • 或者,如果响应不是服务器端的JSON,则将JsonObjectRequest更改为StringRequest
相关问题