W / System.err:org.json.JSONException:java.lang.String类型的值<!-无法转换为JSONObject

时间:2018-12-24 16:59:12

标签: java android

 字符串url = AppConfig.URL_IP +“?register = reg&first_name =” + fname +“&last_name =” + lname +“&email =” + email +“&address =” + address +“&password =” + password +“&number =” + number +“&city =” + city +“&category =” + category;
                        Log.d(“ urlll”,url);
                        StringRequest request = new StringRequest(Request.Method.GET,url,new Response.Listener (){
                            @Override
                            public void onResponse(String response){
                                尝试{
                                    JSONObject jsonObject =新的JSONObject(response);
                                    boolean checkerror = jsonObject.getBoolean(“ error”);
                                    如果(checkerror){
                                        字符串error_message = jsonObject.getString(“ error_msg”);
                                        Toast.makeText(getApplicationContext(),error_message,Toast.LENGTH_SHORT).show();

                                    }其他{
                                        字符串sucess_message = jsonObject.getString(“ sucess_msg”);
                                        Toast.makeText(getApplicationContext(),sucess_message,Toast.LENGTH_SHORT).show();
                                    }
                                } catch(JSONException e){
                                    e.printStackTrace();
                                }
                            }
                        },新的Response.ErrorListener(){
                            @Override
                            公共无效onErrorResponse(VolleyError错误){
                                Toast.makeText(getApplicationContext(),error.getMessage()+“ aaaa”,Toast.LENGTH_SHORT).show();
                            }
                        });
                        AppController.getInstance()。addToRequestQueue(request,“ registerAPI”);
 

它给了我这个错误:

  W / System.err:org.json.JSONException:值<!-类型
java.lang.String无法转换为JSONObject
 

任何人都可以提前解决谢谢。

1 个答案:

答案 0 :(得分:0)

因为您正在尝试将无效的JSON字符串转换为jsonObject。在线检查任何json验证程序工具中的json字符串。 json validator