语法
json.array(source: table): table参数
| 名称 | 类型 | 描述 |
|---|---|---|
source | table | 操作使用的源值。 |
返回值
| 名称 | 类型 | 描述 |
|---|---|---|
array | table | 标记为 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))