title: Android: Parse JSON from url
body: <p>Here is the url <a href="http://gdata.youtube.com/feeds/api/videos/XbGs_qK2PQA?v=2&amp;alt=jsonc" rel="nofollow">JSON</a></p>
  
  <p>I want to parse the JSON and get <code>title</code> from the link and store it to a String. </p>
  
  <p>I have tried other JSON parsing examples but everytime I try those, it either doesn't work or my app crashes.</p>
  
  <p>Code - </p>
  
  <pre><code>//the components are in separate methods
  web = (WebView)this.findViewById(R.id.webView1);
  
      protocol = "https://www.youtube.com/";
      web.getSettings().setJavaScriptEnabled(true);
      WebSettings settings = web.getSettings();  
      settings.setSupportMultipleWindows(false);
      web.setWebChromeClient(new WebChromeClient()); 
      web.setWebViewClient(new WebViewClient());
      web.loadUrl(protocol);
  
      web.setDownloadListener(new DownloadListener() {
          public void onDownloadStart(String url, String userAgent,
                  String contentDisposition, String mimetype,
                  long contentLength) {
              Request request = new Request(
                              Uri.parse(url));
                      request.allowScanningByMediaScanner();
                      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download"); 
                      DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                      dm.enqueue(request);        
  
          }
      });
  //Adding download manager to it. Download manager downloads the youtube video but the title is changed.
  
  //I have action bar button, on click of which the download url of current weburl, converts it into mp3 and redirects user to the download page.
  
  case R.id.action_download:
  
          String aJsonString = "ffff";
  
          final String webUrl = web.getUrl();
          String z = webUrl.substring(30);
  
          protocol = "http://www.youtube-mp3.org/?e=session_expired&amp;t#v=" + z;
          web.loadUrl(protocol);
  
          String json = "http://gdata.youtube.com/feeds/api/videos/" + z + "?v=2&amp;alt=jsonc";
  
          getData();
  //calling your method           
  
          return true;
  
  //your method
  
  public void getData()
  {
      HttpClient httpclient = new DefaultHttpClient();
      httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
      HttpGet request = new HttpGet("http://gdata.youtube.com/feeds/api/videos/XbGs_qK2PQA?v=2&amp;alt=jsonc");
  
      try
      {
      HttpResponse response = httpclient.execute(request);
      HttpEntity resEntity = response.getEntity();
      String _response = EntityUtils.toString(resEntity); 
  
      JSONObject json = new JSONObject(_response);
      JSONObject data = json.getJSONObject("data");
      String tile = data.getString("title");
  
      Toast.makeText(this, tile, Toast.LENGTH_LONG).show();
  
      }catch(Exception e)
      {
              e.printStackTrace();
       }
  
      httpclient.getConnectionManager().shutdown();
  }
  </code></pre>