title: Why json parsing is not working?
body: <p>I'm fetching data through <code>JSON-Parsing</code>, but getting "NullPointerException" and <code>Error A JSONArray text must start with '[' at character 1 of {</code>. following is what I have tried so far :</p>
  
  <pre><code>/** Method for returning JSONObject */
  protected JSONObject lastTweet() {
  
      try {
          HttpGet request = new HttpGet("http://api.androidhive.info/contacts/");
          HttpResponse response = client.execute(request);
          int statusCode = response.getStatusLine().getStatusCode();
          if (statusCode &gt;= 200) {
              HttpEntity entity = response.getEntity();
              String data = EntityUtils.toString(entity);
              JSONArray jsonArray = new JSONArray(data);
              JSONObject lastT = jsonArray.getJSONObject(0);
              return (lastT);
          } else {
              Log.e(MY_TAG, "Error");
              return null;
          }
  
      } catch (ClientProtocolException e) {
          Log.e(MY_TAG, "Error " + e.getMessage());
          return null;
      } catch (IOException e) {
          Log.e(MY_TAG, "Error " + e.getMessage());
          return null;
      } catch (JSONException e) {
          Log.e(MY_TAG, "Error " + e.getMessage());
          return null;
      }
  
  }
  </code></pre>
  
  <p>Now when I actually make this code work for me is following :</p>
  
  <pre><code>new AsyncTask&lt;String, Integer, String&gt;() {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              dialog = new ProgressDialog(MainActivity.this);
              dialog.setTitle("Please wait..");
              dialog.setMessage("Data is being loaded");
              dialog.show();
          }
  
          @Override
          protected String doInBackground(String... params) { // TODO
              try {
                  jsonObject = lastTweet();
                  return jsonObject.getString("name");
              } catch (JSONException e) {
                  return null;
              }
          }
  
          @Override
          protected void onPostExecute(String result) { // TODO
              super.onPostExecute(result);
              textView.setText(result);
              dialog.dismiss();
          }
  
      }.execute(null, null, null);
  </code></pre>
  
  <p>that gives me the following <code>LogCat</code> :</p>
  
  <p><img src="https://i.stack.imgur.com/gduP1.png" alt="Logcat snap shot"></p>
  
  <p>How to solve that issue?</p>