<https://developer.android.com/reference/kotlin/or...
# android
s
https://developer.android.com/reference/kotlin/org/json/JSONObject. I'm trying to use a public method of this class as follows:
Copy code
fun getSource(inp: JSONObject, key: String): String{
    return JSONObject(inp.getString("_source")).optString(key)
}
My ide is saying that the public methods getString and optString are unresolved references. Anyone know what the issue might be?
f
Do you have correct import?
s
I have:
Copy code
open class JSONObject
Do I need something else?
s
If you have defined JSONObject just like the snippet you wrote above, instead of defining it by your own, you should import it to use it
s
Right but what's the import? Is it import org.json? Because then my ide is saying json is an unresolved reference.
f
Try
import org.json.JSONObject
s
Tried that too and my ide still says that json is an unresolved reference
f
Can you post the whole file - relevant JSON code and imports?
s
Problem went away! Just had to add a dependency to a gradle file and then wait a while