显示 JSON - Laravel Blade
Display JSON - Laravel Blade
是否可以在 blade 中按原样显示响应 JSON?喜欢
{{ $collection }}
[
{
"id":1,
"name":"Quam accusantium dolore qui.",
"description":"Ipsa mollitia et rerum sint.",
...
}
]
我希望它像上面那样 well-formatted 以使其更具可读性。
是的,你可以使用 pre tag
<pre>{{ $collection }}</pre>
如果 json 尚未格式化,您也可以使用 JSON_PRETTY_PRINT
作为 param
到 json_encode
的第二个
$data=json_decode('[
{"id":1,"name":"Quam accusantium dolore qui.","description":"Ipsa mollitia et rerum sint."}
]');
return view('welcome',['collection'=>json_encode($data, JSON_PRETTY_PRINT)]);
在你看来
<pre >
<code style="color: #ff12a0;">{{$collection}}</code>
</pre>
要按原样查看 json,您必须使用 html 前置标签
首先像下面这样对您的 json 数据进行编码
$collection = json_decode("Peter"=>35, "Ben"=>37, "Joe"=>43);
在html视图中这样使用
{{ $collection }}
是否可以在 blade 中按原样显示响应 JSON?喜欢
{{ $collection }}
[
{
"id":1,
"name":"Quam accusantium dolore qui.",
"description":"Ipsa mollitia et rerum sint.",
...
}
]
我希望它像上面那样 well-formatted 以使其更具可读性。
是的,你可以使用 pre tag
<pre>{{ $collection }}</pre>
如果 json 尚未格式化,您也可以使用 JSON_PRETTY_PRINT
作为 param
到 json_encode
的第二个
$data=json_decode('[
{"id":1,"name":"Quam accusantium dolore qui.","description":"Ipsa mollitia et rerum sint."}
]');
return view('welcome',['collection'=>json_encode($data, JSON_PRETTY_PRINT)]);
在你看来
<pre >
<code style="color: #ff12a0;">{{$collection}}</code>
</pre>
要按原样查看 json,您必须使用 html 前置标签
首先像下面这样对您的 json 数据进行编码
$collection = json_decode("Peter"=>35, "Ben"=>37, "Joe"=>43);
在html视图中这样使用
{{ $collection }}