W3cubDocs

/Symfony 2.7

Symfony\Component\Serializer\Encoder\JsonDecode

class JsonDecode implements DecoderInterface

Decodes JSON data

Methods

__construct(bool $associative = false, int $depth = 512)

Constructs a new JsonDecode instance.

int getLastError()

Returns the last decoding error (if any).

mixed decode(string $data, string $format, array $context = array())

Decodes data.

bool supportsDecoding(string $format)

Checks whether the deserializer can decode from given format.

Details

public __construct(bool $associative = false, int $depth = 512)

Constructs a new JsonDecode instance.

Parameters

bool $associative True to return the result associative array, false for a nested stdClass hierarchy
int $depth Specifies the recursion depth

public int getLastError()

Returns the last decoding error (if any).

Return Value

int

See also

http://php.net/manual/en/function.json-last-error.php json_last_error

public mixed decode(string $data, string $format, array $context = array())

Decodes data.

Parameters

string $data The encoded JSON string to decode
string $format Must be set to JsonEncoder::FORMAT
array $context An optional set of options for the JSON decoder; see below The $context array is a simple key=>value array, with the following supported keys: jsondecodeassociative: boolean If true, returns the object as associative array. If false, returns the object as nested stdClass If not specified, this method will use the default set in JsonDecode::construct jsondecoderecursion_depth: integer Specifies the maximum recursion depth If not specified, this method will use the default set in JsonDecode::construct json_decode_options: integer Specifies additional options as per documentation for json_decode. Only supported with PHP 5.4.0 and higher

Return Value

mixed

Exceptions

UnexpectedValueException

See also

http://php.net/json_decode json_decode

public bool supportsDecoding(string $format)

Checks whether the deserializer can decode from given format.

Parameters

string $format format name

Return Value

bool

© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Component/Serializer/Encoder/JsonDecode.html