Skip to content

Commit 193968c

Browse files
committed
feature #7204 Added docs for JsonResponse::fromJsonString (javiereguiluz)
This PR was squashed before being merged into the 3.2 branch (closes #7204). Discussion ---------- Added docs for JsonResponse::fromJsonString This fixes #7174. Commits ------- e9a3be0 Added docs for JsonResponse::fromJsonString
2 parents a9683eb + e9a3be0 commit 193968c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

components/http_foundation.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,22 @@ class, which can make this even easier::
548548

549549
use Symfony\Component\HttpFoundation\JsonResponse;
550550

551+
// if you know the data to send when creating the response
552+
$response = new JsonResponse(array('data' => 123));
553+
554+
// if you don't know the data to send when creating the response
551555
$response = new JsonResponse();
552-
$response->setData(array(
553-
'data' => 123
554-
));
556+
// ...
557+
$response->setData(array('data' => 123));
558+
559+
// if the data to send is already encoded in JSON
560+
$response = JsonResponse::fromJsonString('{ "data": 123 }');
561+
562+
.. versionadded:: 3.2
563+
The ``JsonResponse::fromJsonString()`` method was added in Symfony 3.2.
555564

556-
This encodes your array of data to JSON and sets the ``Content-Type`` header
557-
to ``application/json``.
565+
The ``JsonResponse`` class sets the ``Content-Type`` header to
566+
``application/json`` and encodes your data to JSON when needed.
558567

559568
.. caution::
560569

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy