Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit193968c

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::fromJsonStringThisfixes#7174.Commits-------e9a3be0 Added docs for JsonResponse::fromJsonString
2 parentsa9683eb +e9a3be0 commit193968c

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 andsets the ``Content-Type`` header
557-
to``application/json``.
565+
The ``JsonResponse`` classsets 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)

[8]ページ先頭

©2009-2025 Movatter.jp