public function JsonResponse::setData

Sets the data to be sent as json.

Parameters

mixed $data:

Return value

JsonResponse

2 calls to JsonResponse::setData()
AjaxResponse::prepare in drupal/core/lib/Drupal/Core/Ajax/AjaxResponse.php
Sets the response's data to be the array of AJAX commands.
JsonResponse::__construct in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php
Constructor.

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php, line 78

Class

JsonResponse
Response represents an HTTP response in JSON format.

Namespace

Symfony\Component\HttpFoundation

Code

public function setData($data = array()) {

  // root should be JSON object, not array
  if (is_array($data) && 0 === count($data)) {
    $data = new \ArrayObject();
  }

  // Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML.
  $this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
  return $this
    ->update();
}