苗条的框架漂亮 JSON
Slim Framework Pretty JSON
如何配置 Slim Framework 输出漂亮 JSON?
在 PHP 原生中我可以使用这种语法
json_encode($data, JSON_PRETTY_PRINT);
引用自Slim docs:
Slim’s Response object has a custom method withJson($data, $status,
$encodingOptions) to help simplify the process of returning JSON data.
The $data parameter contains the data structure you wish returned as
JSON. $status is optional, and can be used to return a custom HTTP
code. $encodingOptions is optional, and are the same encoding options
used for json_encode().
因此,如果您使用 withJson
到 return JSON 响应,您可以像这样使用它:
return $response->withJson($data, 200, JSON_PRETTY_PRINT);
如何配置 Slim Framework 输出漂亮 JSON?
在 PHP 原生中我可以使用这种语法
json_encode($data, JSON_PRETTY_PRINT);
引用自Slim docs:
Slim’s Response object has a custom method withJson($data, $status, $encodingOptions) to help simplify the process of returning JSON data.
The $data parameter contains the data structure you wish returned as JSON. $status is optional, and can be used to return a custom HTTP code. $encodingOptions is optional, and are the same encoding options used for json_encode().
因此,如果您使用 withJson
到 return JSON 响应,您可以像这样使用它:
return $response->withJson($data, 200, JSON_PRETTY_PRINT);