Skip to main content

参数

string
必填
要 parse 的 JSON text。这个 argument 会在 parse errors 被 catch 之前检查为 string。
DecodeOptions
Optional decode options。boolean 会直接设置 useNull。table 可以设置 useNull 和 maxDepth;maxDepth 会 clamp 到 1 到 4096。Invalid option argument types 会在 parse errors 被 catch 之前检查。

返回值

boolean
parsing 成功时为 True,parser 报告 error 时为 false。
any | nil
成功时的 Decoded value,parse failure 时为 nil。有效的 JSON false 会返回 success 为 true 且 decoded 为 false,因此请检查 success return value。
string | nil
parse failure 时的 Error message,否则为 nil。message 包含 json.decodeSafe prefix 和 parser position。
number | nil
parse failure 时的 Parser byte position,否则为 nil。

类型

DecodeOptions

控制 JSON 解析行为。

示例

Parse JSON,并使用 success return value 区分 valid false 或 nil results 与 parse failures。