语法
json.parse(json: string, options?: DecodeOptions): any参数
| 名称 | 类型 | 描述 |
|---|---|---|
json | string | 要解析、格式化、缩小或验证的 JSON 字符串。 |
options? | DecodeOptions | 控制操作行为方式的可选设置表。 |
返回值
| 名称 | 类型 | 描述 |
|---|---|---|
decoded | any | 解码的 Luau 值或解码的字节字符串。 |
说明
别名样式的 JSON 解析器,其行为类似于 json.decode。
使用 2 个参数调用: json, options。参数表会说明哪些值必填,哪些值只用于细化行为。
返回 decoded (any)。使用返回表区分成功值、nil 结果和可恢复错误。
示例
使用与解码兼容的别名解析 JSON。
local settings = json.parse('{"volume":0.75,"theme":"dark"}')
print(settings.volume)
print(settings.theme)类型
DecodeOptions
控制 JSON 解析行为。
useNull? boolean 使用库的 null 标记而不是 nil 来表示 JSON null。maxDepth? integer 设置最大嵌套深度,范围为 1 到 4096。