title: java.lang.Integer cannot be converted to JSONObject when sending string response from the server
body: <p>I am sending data to server from android application through genAsync library. On server I am inserting and checking if user is already exist simultaneously.if user is already exist than I am sending json_encoded array and if user not exist than im sending <strong>message</strong> that is user inserted successfully but when im sending message to application it gives an error that is  <strong>java.lang.Integer cannot be converted to JSONObject</strong></p>
  
  <p>Im attaching the php codes,android codes and error log also.</p>
  
  <p><strong>php codes</strong></p>
  
  <pre><code>class Users extends CI_Controller
  {
  
    public function create(){
  
      $data=$this-&gt;check_exist($this-&gt;input-&gt;post('user_id'));
      if($data=='0')
      {
  
          $this-&gt;load-&gt;model('UsersModel');
          $msg = $this-&gt;UsersModel-&gt;create();
          if ($msg==true) {
              echo 'user inserted successfully';
          } else {
              echo '0';
          }
      }
      else{
          $data["user_details"]=$data;
          echo json_encode($data);
      }
    }
    public function check_exist($user_id)
      {
        $this-&gt;load-&gt;helper('url');
        $this-&gt;load-&gt;model('UsersModel');
        $data=$this-&gt;UsersModel-&gt;user_exist($user_id);
        if(!empty($data))
        {
          return($data);
        }
        else
        {
          return '0';
        }
     }
  }
  </code></pre>
  
  <p><strong>android codes for sending data to server side</strong></p>
  
  <pre><code>try {
             final Database_Helper dg = new Database_Helper(getBaseContext());
             ServerUrl obj =new ServerUrl();
             HashMap postData = new HashMap();
             postData.put("user_id",personId);
             postData.put("user_name",personName);
             postData.put("email",personEmail);              
             postData.put("profile_picture",String.valueOf(personPhoto));
             final PostResponseAsyncTask readTask = new PostResponseAsyncTask(UserLogin.this, postData, new AsyncResponse() 
                {
  
                  public void processFinish(String mStringArray) 
                    {
                       Log.w("data", mStringArray.toString());
                       try {
                             JSONObject json= null;
                             json = new JSONObject(mStringArray);
                             JSONArray jsonscoresarray=json.getJSONArray("user_details");
                             final JSONObject details = jsonscoresarray.getJSONObject(0);
                            if (jsonscoresarray.length() == 0) 
                            {
                              //storing data to sqlite if user not exist
                              dg.user_Putrecord(dg, personId, personName, personEmail, String.valueOf(personPhoto));
                            }
                            else
                            {
                               //storing data to sqlite if user exist
            dg.user_Putrecord(dg,details.getString("auth_id"),details.getString("full_name"),details.getString("email_id"),details.getString("profile_url"));
                                          }
                                      } catch (JSONException e) {
                                          e.printStackTrace();
                                      }
                                      Toast.makeText(UserLogin.this, mStringArray.toString(), Toast.LENGTH_LONG).show();
                                  }
  
                              });
                              obj.url("Users","create");
                              readTask.execute(obj.domain_url);
                          }
                          catch (Exception ex)
                          {
                           Toast.makeText(UserLogin.this, ex.getMessage().toString(), Toast.LENGTH_SHORT).show();
                          }
  </code></pre>
  
  <p><strong>Here is my error logcat</strong></p>
  
  <pre><code>01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err: org.json.JSONException: Value 1 of type java.lang.Integer cannot be converted to JSONObject
  01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
  01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err:     at org.json.JSONObject.&lt;init&gt;(JSONObject.java:160)
  01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err:     at org.json.JSONObject.&lt;init&gt;(JSONObject.java:173)
  01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err:     at com.example.ali.ansofexperts.UserLogin$4$1.processFinish(UserLogin.java:121)
  01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err:     at com.kosalgeek.asynctask.PostResponseAsyncTask.onPostExecute(PostResponseAsyncTask.java:248)
  01-29 13:49:33.765 4455-4455/com.example.ali.ansofexperts W/System.err:     at com.kosalgeek.asynctask.PostResponseAsyncTask.onPostExecute(PostResponseAsyncTask.java:31)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at android.os.AsyncTask.finish(AsyncTask.java:667)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at android.os.AsyncTask.-wrap1(AsyncTask.java)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at android.os.Looper.loop(Looper.java:154)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6121)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
  01-29 13:49:33.766 4455-4455/com.example.ali.ansofexperts W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
  </code></pre>
  
  <p>i just want to know how can i handle this exception when string  response is sended from server.</p>