title: Android - How to get specific data from URL/JSON?
body: <p>So I have this code, which is a page with a <code>ListView</code> search field and a button to confirm the search, when the button is pressed the <code>ListView</code> is filled with movie names from the Rotten Tomatoes API, The problem is that someone helped me with this code, and I would love some help breaking it down and understanding it sentence after sentence, My main goal is to get is to get the "title", "synopsis" and "url image" of a movie that was clicked in the list, and pass it with an intent to my other activity but the whole JSON and get specific data stuff, got me very confused.</p>
  
  <p><a href="http://developer.rottentomatoes.com/docs" rel="nofollow">Link to Rotten Tomatoes API documentation</a>, this is my code:</p>
  
  <pre><code>public class MovieAddFromWeb extends Activity implements View.OnClickListener,
          OnItemClickListener {
  
      private TextView searchBox;
      private Button bGo, bCancelAddFromWeb;
      private ListView moviesList;
      public List&lt;String&gt; movieTitles;
      static final int ACTIVITY_WEB_ADD = 3;
  
      // the Rotten Tomatoes API key
      private static final String API_KEY = "8q6wh77s65aw435cab9rbzsq";
  
      // the number of movies to show in the list
      private static final int MOVIE_PAGE_LIMIT = 8;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.movie_add_from_web);
  
          InitializeVariables();
  
      }
  
      /*
       * Initializing the variables and creating the bridge between the views from
       * the xml file and this class
       */
  
      private void InitializeVariables() {
  
          searchBox = (EditText) findViewById(R.id.etSearchBox);
          bGo = (Button) findViewById(R.id.bGo);
          bCancelAddFromWeb = (Button) findViewById(R.id.bCancelAddFromWeb);
          moviesList = (ListView) findViewById(R.id.list_movies);
  
          bGo.setOnClickListener(this);
          bCancelAddFromWeb.setOnClickListener(this);
          moviesList.setOnItemClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          switch (v.getId()) {
  
          case R.id.bGo:
              new RequestTask()
                      .execute("http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey="
                              + API_KEY
                              + "&amp;q="
                              + searchBox.getText()
                              + "&amp;page_limit=" + MOVIE_PAGE_LIMIT);
              break;
  
          case R.id.bCancelAddFromWeb:
              finish();
              break;
  
          }
  
      }
  
      private void refreshMoviesList(List&lt;String&gt; movieTitles) {
          moviesList.setAdapter(new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_list_item_1, movieTitles
                          .toArray(new String[movieTitles.size()])));
      }
  
      private class RequestTask extends AsyncTask&lt;String, String, String&gt; {
          // make a request to the specified url
          @Override
          protected String doInBackground(String... uri) {
              HttpClient httpclient = new DefaultHttpClient();
              HttpResponse response;
              String responseString = null;
              try {
                  // make a HTTP request
                  response = httpclient.execute(new HttpGet(uri[0]));
                  StatusLine statusLine = response.getStatusLine();
                  if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                      ByteArrayOutputStream out = new ByteArrayOutputStream();
                      response.getEntity().writeTo(out);
                      out.close();
                      responseString = out.toString();
                  } else {
                      // close connection
                      response.getEntity().getContent().close();
                      throw new IOException(statusLine.getReasonPhrase());
                  }
              } catch (Exception e) {
                  Log.d("Test", "Couldn't make a successful request!");
              }
              return responseString;
          }
  
          @Override
          protected void onPostExecute(String response) {
              super.onPostExecute(response);
  
              try {
                  // convert the String response to a JSON object
                  JSONObject jsonResponse = new JSONObject(response);
  
                  // fetch the array of movies in the response
                  JSONArray jArray = jsonResponse.getJSONArray("movies");
  
                  // add each movie's title to a list
                  movieTitles = new ArrayList&lt;String&gt;();
                  for (int i = 0; i &lt; jArray.length(); i++) {
                      JSONObject movie = jArray.getJSONObject(i);
                      movieTitles.add(movie.getString("title"));
  
                  }
                  // refresh the ListView
                  refreshMoviesList(movieTitles);
              } catch (JSONException e) {
                  Log.d("Test", "Couldn't successfully parse the JSON response!");
              }
          }
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; av, View view, int position, long id) {
  
          Intent openMovieEditor = new Intent(this, MovieEditor.class);
          openMovieEditor.putExtra("movieTitle", movieTitles.get(position));
          openMovieEditor.putExtra("callingActivity", ACTIVITY_WEB_ADD);
          startActivityForResult(openMovieEditor, ACTIVITY_WEB_ADD);
  
      }
  }
  </code></pre>