我有实时json,我想在laravel刀片上显示
我的控制器代码是:
public function index()
{
$json = json_decode(file_get_contents('link_of_json_file'),true);
return view('show' , compact('json'));
}
并且刀片代码为:
@foreach ($json as $p)
{{ $p->name }}
@endforeach
显示此错误:
(2/2)ErrorException
试图获取非对象的属性(查看: E:\ work-landingpage \ test \ JSON \ resources \ views \ show.blade.php)
答案 0 :(得分:3)
您可以删除“ true”以将其用作对象:
public function index()
{
$json = json_decode(file_get_contents('link_of_json_file'));
return view('show' , compact('json'));
}
@foreach ($json as $p)
{{ $p->name}}
@endforeach
因此,如果您想将其用作数组,则可以像这样使用它:
@foreach ($json as $p)
{{ $p['name']}}
@endforeach