【发布时间】:2017-01-05 12:32:57
【问题描述】:
我正在尝试将 JSON 传递给我的视图
使用此代码:
Route::get('json', function() {
$path = storage_path() . "/json/dish.json";
$json = json_decode(file_get_contents($path), true);
return View::make('pages.json')->withJson($json);
});
与{{dd($json)}}
我收到这个:
array:1 [▼
"dish" => array:297 [▼
0 => array:2 [▶]
1 => array:2 [▶]
2 => array:2 [▶]
3 => array:5 [▶]
...
当我尝试显示我的$json 的内容时:
@foreach($json["dish"] as $key => $item)
{{$item}}
@endforeach
我收到此错误消息:
htmlentities() 期望参数 1 是字符串,给定数组(查看:/Users/beyerdynamic/Documents/Developer/dev1/resources/views/pages/json.blade.php)
我在这里做错了什么?
【问题讨论】:
-
$item是一个array。 -
0 => array:2 [▶] 显然 $item 也是一个数组