如何解决显示 JSON - Laravel Blade
是否可以在刀片中按原样显示响应 JSON?喜欢
{{ $collection }}
[
{
"id":1,"name":"Quam accusantium dolore qui.","description":"Ipsa mollitia et rerum sint.",...
}
]
我希望它像上面那样格式良好,以使其更具可读性。
解决方法
是的,您可以使用 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 pre 标记
首先像下面这样编码你的json数据
onApprove: function(data,actions) {
return actions.order.capture().then(function(details) {
console.log(details);
console.log(JSON.stringify( JSON.parse(details),null,2) );
//This is where you should show a success message or redirect.
//If you need to anything that touches a server database,use a server-side create and capture instead of the client-side actions.order.create() / .capture()
});
}
在html视图中像这样使用
{{ $collection }}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。