title: How can I get data from response body?
body: <p>I need to get <code>&quot;status&quot;</code> value from my response. I tried <code>JSONObject</code> but it gave that <em>java.lang.reflect.InvocationTargetException</em> error in the code below. I need that because I make some process with status value like start new activity etc. How can I get this?</p>
  <pre><code>private fun doReq(){
      val client = OkHttpClient().newBuilder()
          .build()
      val mediaType = &quot;application/json;charset=utf-8&quot;.toMediaTypeOrNull()
      val body: RequestBody = jsonSended.toRequestBody(mediaType)
      val request: Request = Request.Builder()
          .url(&quot;https://apiapiapi/auth&quot;)
          .method(&quot;POST&quot;, body)
          .addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;)
          .addHeader(&quot;Authorization&quot;, &quot;$authValue&quot;)
          .addHeader(&quot;x-iyzi-rnd&quot;, &quot;$randomString&quot;)
          .addHeader(&quot;cache-control&quot;, &quot;no-cache&quot;)
          .build()
  
      val response = client.newCall(request).execute()
      println(response.body?.string())  // I CAN GET RESPONSE BODY 
  
      var json = JSONObject(response.body.toString())
      var status = json.getString(&quot;status&quot;)  // HERE NOT WORKING...
  
      println(status)
  
  
  }
  </code></pre>
  <p>In the response when server return failure : <code>{&quot;status&quot;:&quot;failure&quot;,&quot;errorCode&quot;:&quot;12&quot;,&quot;errorMessage&quot;:&quot;invalid&quot;,&quot;locale&quot;:&quot;tr&quot;,&quot;systemTime&quot;:1610022545347,&quot;conversationId&quot;:&quot;123412341234&quot;}</code></p>
  <p>If server return valid my response is very very long but it also have status so I can get that status value and do something with that. Is that correct way to do it? I need advice.</p>