Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. JsonResponse.php

function JsonResponse::fromJsonString

Factory method for chainability.

Example:

return JsonResponse::fromJsonString('{"key": "value"}') ->setSharedMaxAge(300);

Parameters

string $data The JSON response string:

int $status The response status code (200 "OK" by default):

array $headers An array of response headers:

File

vendor/symfony/http-foundation/JsonResponse.php, line 64

Class

JsonResponse
Response represents an HTTP response in JSON format.

Namespace

Symfony\Component\HttpFoundation

Code

public static function fromJsonString(string $data, int $status = 200, array $headers = []) : static {
    return new static($data, $status, $headers, true);
}
RSS feed
Powered by Drupal