title: Can not get value from a JsonArray in Android?
body: <p>I am trying to convert my JsonArray to StringArray but I just couln't get values from the Json array. I use the code below, but in the <code>resultsFollowedUsersVar.getJSONObject(i);</code> part I am getting the error </p>
  
  <pre><code>Unhandled exception, org.JSON.jsonException
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <pre><code> resultsFollowedUsers = new ArrayList&lt;String&gt;();
  resultsFollowedAndPendingUsers = new ArrayList&lt;String&gt;();
  
  resultsFollowedUsers.removeAll(resultsFollowedUsers);
  resultsFollowedAndPendingUsers.removeAll(resultsFollowedAndPendingUsers);
  
  ParseQuery&lt;ParseObject&gt; followedQuery = ParseQuery.getQuery("followCount");
  followedQuery.whereEqualTo("userid", ParseUser.getCurrentUser().getObjectId());
  
  followedQuery.findInBackground(new FindCallback&lt;ParseObject&gt;() {
      @Override
      public void done(List&lt;ParseObject&gt; objects, ParseException e) {
  
          if (e == null) {
  
              for (ParseObject object : objects) {
  
                  JSONArray resultsFollowedUsersVar = object.getJSONArray("followedArray");
                  JSONObject json_obj = null;
  
                  for (int i = 0; i &lt; resultsFollowedUsersVar.length(); i++){
  
                      try {
                          System.out.println("Check if program enters here");
                          System.out.println(resultsFollowedUsersVar.getJSONObject(i));
                          System.out.println(json_obj.toString());
                          json_obj = resultsFollowedUsersVar.getJSONObject(i);
                          resultsFollowedUsers.add(json_obj.toString());
                      }
                      catch(JSONException ex) {
                          ex.printStackTrace();
                      }
                  }
  
                  System.out.println(resultsFollowedUsersVar.toString());
                  System.out.println(resultsFollowedUsers);
  
                  JSONArray resultsFollowedAndPendingUsersVar = object.getJSONArray("followPendingArray");
                  JSONObject json_obj2 = null;
  
                  for(int i = 0; i &lt; resultsFollowedAndPendingUsersVar.length(); i++){
  
                      try{
                          System.out.println("Check if program enters here 2");
                          json_obj2 = resultsFollowedAndPendingUsersVar.getJSONObject(i);
                          resultsFollowedAndPendingUsers.add(json_obj2.toString());
                      }catch(JSONException ex){
                          ex.printStackTrace();
                      }
                  }
  
              }
  
          }
  
          reloadData();
      }
  });
  </code></pre>
  
  <p>The:</p>
  
  <pre><code>System.out.println(resultsFollowedUsersVar.toString())
  </code></pre>
  
  <p>Gives result in log:</p>
  
  <pre><code>  ["WE27P50RyN","eG0KdMIKJd","rsnwFrkc3r","IqKNzdkVw7"]
  </code></pre>
  
  <p>The:</p>
  
  <pre><code>System.out.println(resultsFollowedUsersVar.getJSONObject(i))
  </code></pre>
  
  <p>Gives result in log:</p>
  
  <pre><code>org.json.JSONException: Value IqKNzdkVw7 at 3 of type java.lang.String cannot be converted to JSONObject
  </code></pre>
  
  <p>Edit:  I finally got the solution, I was retrieving the array from parse in a wrong method, I finally made it as below:</p>
  
  <pre><code>                    resultsFollowedUsers = new ArrayList&lt;String&gt;();
                      resultsFollowedAndPendingUsers = new ArrayList&lt;String&gt;();
  
                      resultsFollowedUsers.removeAll(resultsFollowedUsers);
                      resultsFollowedAndPendingUsers.removeAll(resultsFollowedAndPendingUsers);
  
                      ParseQuery&lt;ParseObject&gt; followedQuery = ParseQuery.getQuery("followCount");
                      followedQuery.whereEqualTo("userid", ParseUser.getCurrentUser().getObjectId());
  
                      followedQuery.findInBackground(new FindCallback&lt;ParseObject&gt;() {
                          @Override
                          public void done(List&lt;ParseObject&gt; objects, ParseException e) {
  
                              if (e == null) {
  
                                  for (ParseObject object : objects) {
  
                                      resultsFollowedUsers = (ArrayList&lt;String&gt;) object.get("followedArray");
                                      resultsFollowedAndPendingUsers = (ArrayList&lt;String&gt;) object.get("followPendingArray");
  
                                      System.out.println(resultsFollowedUsers);
                                      System.out.println(resultsImageFiles);
  
                                  }
  
                              }
  
                              reloadData();
                          }
                      });
  </code></pre>