Laravel JSON 输出格式

我有一个子页面,为每个表绘制字母。例如,我给出1、2、3、4、5和a、b、c。下面是处理结果的代码:


@extends('layout')

@section('content')

    <div class="card mt-5">

        <div class="card-header" style="z-index: 1000;">

            <h2>Results {{response()->json([$teams_json])->getContent()}}</h2>

        </div>     

    </div>

@endsection

JSON 响应的结果:


Result: [{"a":["2","3"],"b":["1","5"],"c":["4"]}]

如何将结果格式化为如下所示?


Result:

   - a: 2,3

   - b: 1,5

   - c: 4


千巷猫影
浏览 120回答 1
1回答

幕布斯7119047

您必须循环播放并按照您希望的方式打印它们。由于您使用的是 Blade,因此您可以使用@foreach.请尝试以下操作:@extends('layout')@section('content')&nbsp; &nbsp; <div class="card mt-5">&nbsp; &nbsp; &nbsp; &nbsp; <div class="card-header" style="z-index: 1000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h2>Results {{response()->json([$teams_json])->getContent()}}</h2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @foreach ($teams_json as $team => $no)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{ $team }}: {{ implode($no) }}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @endforeach&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; </div>@endsection
打开App,查看更多内容
随时随地看视频慕课网APP