は、私はJSONデータを以下している国のデータにはブレードに表示するコントローラーからJSONデータを送信する:Laravel 5.2以下
class CountryData {
public function GetCountries() {
return response()->json(['Data' => \App\Models\CountryModel::all()]);
}
}
を返すクラスは、機能上
HTTP/1.0 200 OK Cache-Control: no-cache Content-Type: application/json
{
"Data":[
{
"CountryID" : 1,
"Country" : "United States",
"CountryCode": "US"
}
]
}
をすることによって返されます以下はコントローラのコードです。以下は
$Countries = (new \App\DataAccess\CountryData())->GetCountries();
return view('Country.List')->with('Countries', json_decode($Countries));
ビューのコード
@foreach($Countries["Data"] as $Country)
<tr class="odd pointer">
<td class=" ">{{$Country["Country"]}}</td>
<td class=" ">{{$Country["CountryCode"]}}</td>
</tr>
@endforeach
私はecho $Countries;
を入力すると、私はテキストの上取得することです。私がecho json_decode($Countries, true);
と入力すると、それは空白になります。なぜこれが起こっているのか教えてください。
理由以下のコードを使用してデータがBladeに渡されているため、この処理を行っています。
$Countries = (new \App\DataAccess\CountryData())->GetCountries();
return view('Country.List')->with('Countries', json_decode($Countries));
だから、正確に何を達成したいですか? –
Blendのレコードのリストを表示するためにJson Dataを読んでいます。 – Pankaj