gpt4 book ai didi

php - Laravel 4 JSON 输出格式

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:31 28 4
gpt4 key购买 nike

return Response::json(array(
'status' => 200,
'posts' => $post->toArray()
), 200);

使用上面的代码,我返回了 json 格式的数据。
我已经看到其他返回 json 的 api 在格式化 View 中返回它。
喜欢:

http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=440&count=3&maxlength=300&format=json

但是我的是在一行中返回它。如何使用 laravel 以格式化的方式生成 json?


更新

我明天才能测试代码。所以我会接受汤姆的回答。

但这是api

http://laravel.com/api/class-Illuminate.Support.Facades.Response.html

参数是,

$data
$status
$headers

更新

实际上我修改了 illuminate 的响应类以具有该常量。

最佳答案

目前4.2版本可以。

Response::json($data=[], $status=200, $headers=[], $options=JSON_PRETTY_PRINT);

https://github.com/laravel/framework/commit/417f539803ce96eeab7b420d8b03f04959a603e9

关于php - Laravel 4 JSON 输出格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20678732/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com