• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/engine/response/json.php
  • Класс: BitrixMainEngineResponseJson
  • Вызов: Json::setData
public function setData($data)
{
	//todo It's a crutch. While we are supporting php 5.3 we have to keep this code.
	//When minimal version is php 5.5 we can implement JsonSerializable in DateTime, Uri and remove this code.
	$data = $this->processData($data);

	if ($data instanceof JsonSerializable)
	{
		$this->data = MainWebJson::encode($data->jsonSerialize(), $this->jsonEncodingOptions);
	}
	elseif ($data instanceof ContractJsonable)
	{
		$this->data = $data->toJson($this->jsonEncodingOptions);
	}
	elseif ($data instanceof ContractArrayable)
	{
		$this->data = MainWebJson::encode($data->toArray(), $this->jsonEncodingOptions);
	}
	else
	{
		$this->data = MainWebJson::encode($data, $this->jsonEncodingOptions);
	}

	return $this->setContent($this->data);
}