Skip to main content

参数

any
必填
要 encoded 的 value。nil、booleans、numbers、strings、tables 和 json.null 会直接处理。Unsupported Lua types 会 encoded 为 null,除非 errorOnUnsupported 为 true。
EncodeOptions
Optional encode options。json.pretty 读取与 json.encodePretty 相同的 options,然后强制 pretty 为 true。没有 options 时使用 two-space indent。number 设置 indent width 并 clamp 到 0.16,string 设置 indent text,table 可以设置 sortKeys、emptyTableAsArray、errorOnUnsupported、encodeInvalidNumbersAsNull、maxDepth 和 indent。

返回值

string
Readable formatted JSON string。Encoding errors 会作为 Luau errors 抛出。

类型

EncodeOptions

控制 JSON 序列化和格式设置。

示例

使用 json.encodePretty alias 将 JSON-compatible values encode 为 readable formatted JSON。