title: Java HttpURLConnection Returns JSON
body: <p>I'm trying to make a http get request which returns a json response. I need some of the values from the json response to be stored in my session. I have this:</p>
  
  <pre><code>public String getSessionKey(){
      BufferedReader rd  = null;
      StringBuilder sb = null;
      String line = null;
      try {
           URL url = new URL(//url here);
           HttpURLConnection connection = (HttpURLConnection) url.openConnection();
           connection.setRequestMethod("GET");
           connection.connect();
           rd  = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            sb = new StringBuilder();
  
            while ((line = rd.readLine()) != null)
            {
                sb.append(line + '\n');
            }
            return sb.toString();
  
       } catch (MalformedURLException e) {
           e.printStackTrace();
       } catch (ProtocolException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
  
      return "";
  }
  </code></pre>
  
  <p>This returns the JSON in a string:</p>
  
  <pre><code>{ "StatusCode": 0, "StatusInfo": "Processed and Logged OK", "CustomerName": "Mr API"}
  </code></pre>
  
  <p>I need to store StatusCode and CustomerName in the session. How do I deal with returning JSON with java? </p>
  
  <p>Thanks</p>