Search code examples
jsonkotlinimport

Unresolved reference: json


When I build a kotlin project with cradle, I cannot use import org.json.JSONObject, and the json package is not in my library. How can I import it?

import org.json.JSONObject

I use kotlin with gradle. In build.gradle.kts:

dependencies {
    testImplementation(kotlin("test"))
}

Solution

  • Just add implementation dependency into your build.gradle.kts

    dependencies {
        implementation("org.json:json:20240303")
    
        testImplementation(kotlin("test"))
    }