R
R
Rrra2021-12-18 19:58:09
Java
Rrra, 2021-12-18 19:58:09

How to import a Java class into a Kotlin console project?

import java.io.File //Этот класс импортируется нормально
import org.json.JSONArray // Здесь ошибка - Unresolved reference: json
import org.json.JSONTokener // И здесь - Unresolved reference: json

fun main() {
    val file = File("some.json").bufferedReader().readText()
    val obj = JSONTokener(file).nextValue() as JSONArray
}


I'm making a console project in Intellij idea and can't import org.json.JSONArray and org.json.JSONTokener.
I know about other ways of parsing JSON, it is the problem of these two imports that interests me.
Can you please tell me what to change / add to solve the problem?

This is what build.gradle.kts looks like
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.6.10"
    application
}

group = "me.user"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("org.jetbrains.kotlin:kotlin-test:1.6.0")
}

tasks.test {
    useJUnit()
}

tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClass.set("MainKt")
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2021-12-18
@Rrra

And who will connect to the project?
// https://mvnrepository.com/artifact/org.json/json
implementation("org.json:json:20211205")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question