title: Reading an URL to parse json, with Gson, Java
body: <p>Well I have been working on parsing a bit of Json. I got this json from a website and stored it locally so I could also test it offline. But now I want to change it and read it directly from the URL (e.g. <a href="http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson" rel="nofollow">http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson</a>) I thought this would be an easy task but I can't seems to figure it out. This is an example of what Ii have so far.</p>
  
  <p>main class: memberToJava.java</p>
  
  <pre><code>public class memberToJava {
  
      public static void main(String[] args) throws FileNotFoundException {
  
          BufferedReader json = new BufferedReader(new FileReader("...Member.json")); 
  
  
          memberClass memberClass = new Gson().fromJson(json, memberClass.class);
  
          System.out.println("Id: " + memberClass.getMember().get(1).getId());  
      }
  }
  </code></pre>
  
  <p><strong>Solution</strong></p>
  
  <pre><code>public class memberToJava {
  
      public static void main(String[] args) throws FileNotFoundException {
  
      URL url = new URL(//URL Here);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              connection.setRequestMethod("GET");
              connection.connect();
  
      BufferedReader json  = new BufferedReader(new InputStreamReader(connection.getInputStream()));          
  
          memberClass memberClass = new Gson().fromJson(json, memberClass.class);
  
          System.out.println("Id: " + memberClass.getMember().get(1).getId());  
      }
  }
  </code></pre>