当我尝试注册JSONArrayRequest时

时间:2017-06-29 09:16:53

标签: java android

我收到此消息com.android.volley.ParseError:org.json.JSONException:值类型为java.lang.String的电子邮件无法转换为JSONObjectError 我没有得到任何回复..

JsonObjectRequest jsr = new JsonObjectRequest(Request.Method.POST,REGISTER_URL,params,new Response.Listener(){

            @Override
            public void onResponse(JSONObject response) {
                Log.d(TAG, response.toString() + "Response");
                                }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(TAG, error + "Error");
                if( error instanceof ParseError) {

                }

            }
        })
        {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                return headers;
            }
        };
           /**
         * Set Time duration for Register Screen and and put JsonObjectRequest in volley RequestQueue Class.
         * and take action according to RequestQueue Class.
                */
                jsr.setRetryPolicy(new DefaultRetryPolicy(60000,
                        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

            RequestQueue requestQueue = Volley.newRequestQueue(Registers.this);
            requestQueue.add(jsr);
            break;

    }
    }

当我尝试使用StringRequest注册时,我在Backend中收到此消息..

WARN 10024 --- [nio-6060-exec-5] .wsmsDefaultHandlerExceptionResolver:无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:无法读取JSON文档:无法识别的令牌&#39; phoneno& #39;:期待(&#39; true&#39;,&#39; false&#39;或&#39; null&#39;)

            StringRequest sr = new StringRequest(Request.Method.POST, REGISTER_URL, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d(TAG,response.toString());
                        JSONObject params = new JSONObject();
                        try {
                            params.put("name", finalNAME);
                            params.put("email", finalMail);
                            params.put("city", finalCITY);
                            params.put("password", finalPASSWORD);
                            params.put("phoneno", finalMobile);

                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }

                    }
            },new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG,error.toString());
                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("city", finalCITY);
                    params.put("email", finalMail);
                    params.put("name", finalNAME);
                    params.put("password", finalPASSWORD);
                    params.put("phoneno", finalMobile);
                    return params;
                }

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                   *//* params.put("name", finalNAME1);
                    params.put("email", finalMail1);
                    params.put("city", finalCITY);
                    params.put("password", finalPASSWORD);
                    params.put("phoneno", finalMobile);
                   *//* params.put("Content-Type", "application/json; charset=utf-8");
                    return params;
                }
            };
            sr.setRetryPolicy(new DefaultRetryPolicy(60000,
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

            RequestQueue requestQueue = Volley.newRequestQueue(Registers.this);
            requestQueue.add(sr);
            break;
    }}

0 个答案:

没有答案