JsonTrait
Trait to add functions for JSON conversion.
Classes which use this trait must implement the ArrayCopyable interface.
It is recommended that classes which use this trait declare they implement the Jsonable interface.
Table of Contents
- fromJson() : static
- Convert a JSON string into an instance of this class.
- toJson() : string
- Convert this object into a JSON string.
Methods
fromJson()
Convert a JSON string into an instance of this class.
public
static fromJson(string $json) : static
This static function returns a new instance of this class.
If $json
is null
or the type of $json
is not string
,
null
is returned.
Parameters
- $json : string
-
A JSON string.
Return values
static —An instance of this class.
toJson()
Convert this object into a JSON string.
public
toJson(int $options) : string
Parameters
- $options : int
-
Options passed to
json_encode()
. This parameter is optional and its default value is 0.
Return values
string —A JSON string.