Json

Wrapper for a native JSON object.

This class is an implementation of a simple JSON object.

Since it is based on Pointer, all methods in this class do not require to be run on the main thread, however they require you to run them always on the same thread. To pass it a different thread, you can change its thread but beware of the possible consequences.

Please read documentation of Pointer on how you should manage pointer's lifetime.

Constructors

Link copied to clipboard
constructor()
Create a null JSON object.
constructor(value: Boolean)
Create a boolean JSON object.
constructor(value: Double)
Create a double-precision floating-point JSON object.
constructor(value: Int)
Create an integer JSON object.
constructor(value: Long)
Create an integer JSON object.
constructor(@NonNull value: Json.Array)
Create an array JSON object.
constructor(@NonNull value: Json.Dict)
Create a dictionary JSON object.
constructor(@NonNull value: String)
Create a string JSON object.

Types

Link copied to clipboard
JSON array.
Link copied to clipboard
JSON dictionary.
Link copied to clipboard
annotation class Type
JSON value type.

Properties

Link copied to clipboard
val ARRAY: Int = 2
Array type.
Link copied to clipboard
val BOOL: Int = 4
Boolean value type.
Link copied to clipboard
val DICT: Int = 3
Dictionary type.
Link copied to clipboard
val DOUBLE: Int = 6
Double-precision floating-point number type.
Link copied to clipboard
val INT: Int = 5
Long integer type.
Link copied to clipboard
val NULL: Int = 0
No value type.
Link copied to clipboard
val STRING: Int = 1
String type.

Functions

Link copied to clipboard
Return the JSON object as array.
Link copied to clipboard
open fun asBool(): Boolean
open fun asBool(def: Boolean): Boolean
Return the JSON object as boolean value.
Link copied to clipboard
Return the JSON object as dictionary.
Link copied to clipboard
open fun asDouble(def: Double): Double
Return the JSON object as double-precision floating-point number.
Link copied to clipboard
open fun asInt(): Integer
open fun asInt(def: Int): Int
Return the JSON object as integer.
Link copied to clipboard
open fun asLong(): Long
open fun asLong(def: Long): Long
Return the JSON object as long integer.
Link copied to clipboard
Return the JSON object as string.
Link copied to clipboard
open fun changeThread()
Change thread this pointer can be accessed from to the current one.
Link copied to clipboard
open fun clone(): Json
Deep-copy the JSON object.
Link copied to clipboard
open fun close()
Close the native pointer.
abstract fun close()
Link copied to clipboard
open fun dump(@NonNull stream: OutputStream)
Dump the JSON object to an output stream.
Link copied to clipboard
open fun equals(@Nullable o: Any): Boolean
Check if the JSON object is equal to another object.
Link copied to clipboard
open fun get(): Any
Return as a value object.
Link copied to clipboard
open fun getAtPath(@NonNull path: String): Json
Get JSON object at path.
Link copied to clipboard
open fun getBool(): Boolean
Return the value converted to a boolean.
Link copied to clipboard
open fun getDouble(): Double
Return the value converted to a double-precision floating-point number.
Link copied to clipboard
open fun getInt(): Int
Return the value converted to an integer.
Link copied to clipboard
open fun getLong(): Long
Return the value converted to a long integer.
Link copied to clipboard
Return the value converted to a string.
Link copied to clipboard
open fun getType(): Int
Get type of the JSON object.
Link copied to clipboard
open fun hashCode(): Int
Get hash code.
Link copied to clipboard
open fun isArray(): Boolean
Check if the JSON object is an array.
Link copied to clipboard
open fun isBool(): Boolean
Check if the JSON object is a boolean.
Link copied to clipboard
open fun isClosed(): Boolean
Check if the native pointer is closed.
Link copied to clipboard
open fun isDict(): Boolean
Check if the JSON object is a dictionary.
Link copied to clipboard
open fun isDouble(): Boolean
Check if the JSON object is a double-precision floating-point number.
Link copied to clipboard
open fun isInt(): Boolean
Check if the JSON object is an integer.
Link copied to clipboard
open fun isMutable(): Boolean
Check if the native pointer is mutable.
Link copied to clipboard
open fun isNull(): Boolean
Check if the JSON object is a null.
Link copied to clipboard
open fun isSamePointer(@NonNull other: Pointer): Boolean
Check if the pointer is the same as in another pointer.
Link copied to clipboard
open fun isString(): Boolean
Check if the JSON object is a string.
Link copied to clipboard
open fun parse(@Nullable file: File): Json
Parse a file with JSON into a tree.
open fun parse(@Nullable stream: InputStream): Json
open fun parse(@Nullable json: String): Json
Parse a JSON string into a tree.
Link copied to clipboard
open fun reset()
Reset the JSON object.
Link copied to clipboard
open fun set(value: Boolean)
Set to a boolean value.
open fun set(@NonNull array: Json.Array)
Set to an array.
open fun set(@NonNull dict: Json.Dict)
Set to a dictionary.
open fun set(value: Double)
Set to a double-precision floating-point number.
open fun set(@NonNull string: String)
Set to a string.
open fun set(value: Long)
Set to an integer.
Link copied to clipboard
open fun setType(type: Int)
Set type of the JSON object.
Link copied to clipboard
open fun toJson(@Nullable object: Any): Json
Create JSON from Java object.
Link copied to clipboard
open fun toString(): String
open fun toString(pretty: Boolean): String
Return the JSON object as a JSON string.