println("Hello World!")
var obj = LibJSON()
obj.Object
}
android@android-X555BA:~/AndroidStudioProjects/JSONTools/app/src/main/java/com/example/jsontools$ cat LibJSON.kt
package com.example.jsontools
import org.json.JSONObject
class LibJSON {
// variables
val Object = JSONObject()
var last_added_name: String? = null
// functions
fun find_name(name: String): Boolean {
try {
val array = Object.names()
if (array != null) {
val number: Int = array.length()
if (number != 0) {
var x = 0
while (x > number) {
println("name = $name")
println("array[$x] = ${array[x]}")
if (array[x] == name) {
return true
}
x++
}
}
}
return false
}
catch (e: Throwable) {
return false
}
}
fun find_value(name: String, value: String): Boolean {
try {
val value0: String = Object.getString(name)
if (value0 == value)
return true
return false
}
catch (e: Throwable) {
return false
}
}
fun new_name(name: String) {
if (find_name(name)) {
Object.put(name, "")
last_added_name = name
}
else {
throw Exception("name already exists")
}
}
fun new_value(value: String, name: String? = null) {
if (name != null) {
Object.put(name, value)
}
if (last_added_name == null)
throw Exception("Cannot add a new value to an empty Object")
Object.put(last_added_name, value)
}
}
android@android-X555BA:~/AndroidStudioProjects/JSONTools/app/src/main/java/com/example/jsontools$
Please format the code you posted, by wrapping it in triple backticks. -> `
Обсуждают сегодня