-4

This is my JSON data which is I am getting from the server {"success":1,"message":"Thanks for the register."}. I want to extract this 1 from the success. Please help me how should I so this.

 @Override
        protected void onPostExecute(String result) {

            try {
                JSONObject reader= new JSONObject(result);
                JSONObject obj1 = reader.getJSONObject("success");
                String check = obj1.toString();


                if (check.equals("3")) {

                    Toast.makeText(SignUpActivity.this, "You are already registered with us",
                            Toast.LENGTH_LONG).show();

                    emailText.setText("");

                   Intent intent = new Intent(SignUpActivity.this,ReferalIdActivity.class);
                    startActivity(intent);

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

the success field is an Integer not a JsonObject, you need to read it like this : reader.getInt("success");

Oussema Aroua
  • 5,225
  • 1
  • 24
  • 44