Json

interface Json : Variable

提供一套用于处理 JSON 数据的 API,是对 Gson 库的封装, 作为脚本环境中的 json 全局变量接口。

这个接口提供了 JSON 字符串与可变的 JsonElement 之间的相互转换, 以及创建 JsonObjectJsonArrayJsonPrimitive 的能力。

Author

M8Test, [email protected], https://m8test.com

Functions

Link copied to clipboard

创建一个包含布尔值的 JsonPrimitive

Link copied to clipboard
abstract fun createJsonArray(): JsonArray

创建一个空的可变的 JsonArray

Link copied to clipboard

创建一个空的可变的 JsonObject

Link copied to clipboard

创建一个包含数字值的 JsonPrimitive

Link copied to clipboard

创建一个包含字符串值的 JsonPrimitive

Link copied to clipboard
abstract fun decodeFromString(json: String): JsonElement

将一个 JSON 格式的字符串解码为一个通用的 JsonElement 对象。

Link copied to clipboard
abstract fun encodeToString(value: JsonElement): String

将一个 JsonElement 对象编码为 JSON 格式的字符串。

Link copied to clipboard
abstract fun getGlobalName(): String

获取作为全局变量时的名称.

Link copied to clipboard
abstract fun getPublicType(): Type

获取 Variable 注入到脚本时需要显示的类型.

Link copied to clipboard
abstract fun isPrefixRequired(): Boolean

是否需要添加前缀, 每种编程语言添加的前缀不一样, 前缀可以通过 Language.getVariablePrefix 获取.

Link copied to clipboard
abstract fun isSuffixRequired(): Boolean

是否需要添加后缀, 每种编程语言添加的后缀不一样, 后缀可以通过 Language.getVariableSuffix 获取.

Link copied to clipboard
abstract fun toJsonArrayOrNull(element: JsonElement): JsonArray?

尝试将一个 JsonElement 转换为 JsonArray

Link copied to clipboard
abstract fun toJsonObjectOrNull(element: JsonElement): JsonObject?

尝试将一个 JsonElement 转换为 JsonObject

Link copied to clipboard

尝试将一个 JsonElement 转换为 JsonPrimitive