title: How to access the values of HTTP Response object in java
body: <p>I'm sending a request to a server and getting the response to a Response object. It outputs a Json object in postman. I need to know the way to access the values in it. Here's my code.</p>
  
  <pre><code>public void onResponse(Call call, Response response) throws IOException {
      if (!response.isSuccessful()) {
          throw new IOException("Unexpected code " + response);
      }
  
      if(response.code() == 200) {
          //need to access the response object
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Here's the output at postman for the same request</p>
  
  <pre><code>[
      {
          "id": 1,
          "name": "a"
      },
      {
          "id": 2,
          "name": "Udana"
      },
  ]
  </code></pre>
  
  <p>When I try it this way 
      JSONObject jsonObject = new JSONObject(response.toString());</p>
  
  <p>it gives the following error</p>
  
  <p>W/System.err: org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject</p>