title: GET request using Gson (java)
body: <p>I'm pretty sure I'm close to getting this right....</p>
  
  <p>I'm making a request to this url: "<a href="http://svc.metrotransit.org/NexTrip?format=json" rel="nofollow noreferrer">http://svc.metrotransit.org/NexTrip?format=json</a>" (at <a href="http://svc.metrotransit.org/" rel="nofollow noreferrer">http://svc.metrotransit.org/</a>)
  and the output format looks like so:</p>
  
  <pre><code>[{
  "Description":"String content",
  "ProviderID":"String content",
  "Route":"String content"
  }]
  </code></pre>
  
  <p>With the below code I currently have, I get a java.io.FileNotFoundException when executing the line:</p>
  
  <pre><code>JsonElement element = jp.parse(new 
  InputStreamReader((InputStream)request.getContent()));
  </code></pre>
  
  <p>- obviously something is off since I'm not experienced in web requests whatsoever but I'm really not sure what.
  Essentially, all I want to get is the string content of the "route" element but I'm not quite sure if I'm properly doing that (say if my code actually compiles).</p>
  
  <pre><code>    URL url = null;
      HttpURLConnection request;
      try
      {
          url = new URL("http://svc.metrotransit.org/NexTrip?format=json");
          request = (HttpURLConnection)url.openConnection();
          request.setDoOutput(true);
          request.setRequestMethod("GET");
  
          request.connect();
          JsonParser jp = new JsonParser();
          JsonElement element = jp.parse(new 
  InputStreamReader((InputStream)request.getContent()));
          JsonObject obj = element.getAsJsonObject();
  
          String routeID = null;
          if (request.getResponseCode() == HttpURLConnection.HTTP_OK)
          {
              //parse json object
              routeID = obj.get("Route").getAsString();
          }
      }
      catch(IOException e)
      {
          e.printStackTrace();
      }
  </code></pre>