JSONObject获得null响应

时间:2016-10-25 07:26:56

标签: android json

StringRequest strReq = new StringRequest(Request.Method.POST,
               Config.URL_REGISTER, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d("Response", "Register Response: " + response.toString());

                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getString("result").equals("success")) {



                        Toast.makeText(getApplicationContext(),jsonObject.getString("message"), Toast.LENGTH_LONG).show();

                        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString("id","");
                        editor.putString("email", email);
                        editor.putString("user_name", userName);
                        editor.putString("user_pass", userPass);
                        editor.putString("confirm_pass", confirmPassword);

                        Intent intent = new Intent(
                                RegisterActivity.this,
                                MainActivity.class);
                        startActivity(intent);
                        finish();
                    }

logcat的:

注册响应:null

  

org.json.JSONException:类型为org.json.JSONObject $ 1的值null   无法转换为JSONObject

2 个答案:

答案 0 :(得分:0)

这是网址:http://pkmnd.in/rahul/register.php 我在浏览器中获得预期的响应.. {“结果”:“失败”,“消息”:“请输入有效的电子邮件”}

答案 1 :(得分:0)

您的JSON响应无效...告诉后端从json响应中删除文本前端。以下是您的JSON响应&gt;&gt;

here2005{"result":"fail","message":"Please enter a valid email"}