JSON 编码解码类

属性
命名空间 fize\crypt
类名 Json
方法:
方法名 说明
decode() 对 JSON 格式的字符串进行编码
encode() 对变量进行 JSON 编码
lastErrorMsg() 获取最后的错误描述
lastError() 返回最后发生的错误

方法

decode()

对 JSON 格式的字符串进行编码

public static function decode (

    string $json,

    bool $assoc = true,

    int $depth = 512,

    int $options = 0

) : array|object
参数:
名称 说明
json 待解码的 json 格式的字符串。
assoc 当该参数为TRUE时,将返回array而非object。默认为true
depth 指定递归深度,默认为512
options 额外选项,如 JSON_BIGINT_AS_STRING 将数字做为字符串返回

encode()

对变量进行 JSON 编码

public static function encode (

    mixed $value,

    int $options = 0,

    int $depth = 512

) : string
参数:
名称 说明
value 待编码的 value ,除了 resource 类型之外,可以为任何数据类型
options 选项
depth 设置最大深度
该函数只能接受 UTF-8 编码的数据

lastErrorMsg()

获取最后的错误描述

public static function lastErrorMsg () : string

lastError()

返回最后发生的错误

public static function lastError () : int