JsonSerializable::jsonSerializeSpecify data which should be serialized to JSON Description
abstract public mixed JsonSerializable::jsonSerialize
( void
)
Serializes the object to a value that can be serialized natively by json_encode. ParametersThis function has no parameters. Return ValuesReturns data which can be serialized by json_encode, which is a value of any type other than a resource. Examples
Example #1 JsonSerializable::jsonSerialize example returning an array
<?phpThe above example will output:
[
1,
2,
3
]
Example #2 JsonSerializable::jsonSerialize example returning an associative array
<?phpThe above example will output:
{
"foo": "bar",
"quux": "baz"
}
Example #3 JsonSerializable::jsonSerialize example returning an integer
<?phpThe above example will output: 1 Example #4 JsonSerializable::jsonSerialize example returning a string
<?phpThe above example will output: "Hello!" |