Documentation

Json

Class \Bitrix\Main\Engine\Response\Json generates JSON response of arbitrary structure. Automatically coverts data to JSON, UTF-8, if required and assigns header application/json; charset=UTF-8.

Example

new \Bitrix\Main\Engine\Response\Json('ping-pong');
/**
Content-Type: application/json; charset=UTF-8
"ping-pong"
**/

new \Bitrix\Main\Engine\Response\Json([
    'id' => 2208,
    'type' => 'license',
]);

/**
Content-Type: application/json; charset=UTF-8
{"id": 2208, "type": "license"}
**/

Methods

Method Description Available from version
__construct(
   $data = null,
   $options = 0
)
Class constructor. Parameters:
  • $data {mixed} - JSON-response data. Must be converted to JSON format by PHP mechanisms or by implementing one of the following interfaces:
    \JsonSerializable
    \Bitrix\Main\Type\Contract\Jsonable
    \Bitrix\Main\Type\Contract\Arrayable
  • $options {int} Passes in json_encode, by second argument.
setData(
   $data
)
Re-sets JSON-response data. Must be converted ti JSON format by PHP mechanisms or by implementing one of the following interfaces:
\JsonSerializable
\Bitrix\Main\Type\Contract\Jsonable
\Bitrix\Main\Type\Contract\Arrayable
© «Bitrix24», 2001-2024
Up