title: How do I convert a string to a JSONObject in kotlin from openweather response?
body: <p>I would like some help converting an openweather response to a JSONObject right now I am able to get the response using this class.</p>
  <pre><code>import java.net.URL
  
  class ConexionClima {
  
  public fun conseguirRespuestaDeAPI(lat: Double, lon: Double): String ?{
  
      val apiKey: String = &quot;99ccac116e6924f62f669458a754299c&quot;
      var respuesta: String?
      val urlStr = &quot;https://api.openweathermap.org/data/2.5/onecall?lat=2.0&amp;lon=1.0&amp;appid=99ccac116e6924f62f669458a754299c&quot;
  
      try{
          respuesta = URL(urlStr).readText(Charsets.UTF_8)
      } catch (e: Exception) {
          respuesta = null
      }
      return respuesta
    }
  
  
  }
  </code></pre>
  <p>But when I try to convert it using this function</p>
  <pre><code>fun resolverPrimerProblema(latitud: Double, longitud: Double): String{
      val cc = ConexionClima()
      val datos : String? = cc.conseguirRespuestaDeAPI(latitud, longitud)
      if (datos != null) {
          val datosJson = JSONObject(datos)
      }
  
      return(&quot;&quot;)
  }
  </code></pre>
  <p>It just says that &quot;datosJson&quot; is set to null even though the string used is not null and is the response from openWeather. I know this from debugging.</p>
  <p>Can someone tell me what am I doing wrong or what the correct way of doing this is?</p>
  <p>Thanks in advance!</p>