JSON

json.array

将表标记为 JSON 数组,以便编码保留数组语义,包括空表。

语法

json.array(source: table): table

参数

名称类型描述
sourcetable操作使用的源值。

返回值

名称类型描述
arraytable标记为 JSON 数组编码的表。

说明

将表标记为 JSON 数组,以便编码保留数组语义,包括空表。

使用 1 个参数调用: source。参数表会说明哪些值必填,哪些值只用于细化行为。

返回 array (table)。使用返回表区分成功值、nil 结果和可恢复错误。

示例

将表标记为 JSON 数组,包括当它为空时。

local tags = json.array({ "api", "docs", "luau" })
local empty = json.array()

print(json.encode(tags))
print(json.encode(empty))