我正在尝试遍历facebook图表api提供的数组。初始数组包含两个字段(数据和分页)。数据字段也是一个填充了50多个项目的数组。
array:2 [▼
"data" => array:77 [▶]
"paging" => array:2 [▶]
]
并打开:
array:2 [▼
"data" => array:77 [▼
0 => array:5 [▼
"id" => "238123092879087er098234_28365"
"picture" => "https://scontent.xx.fbcdn.net/hphotos-xft1/v/t1.0-0/s130x130/12235138_10we2133658asdasdfafsasf5816390956_3188793651778686071_n.jpg?oh=eb8f907a1e8df5efe99cb2b9fafa9c05&oe=56E5627B"
"message" => """
some new GIN available @ TasTToe!!\n
\n
MASCARO 9 GIN 40°\n
Alkkemist GIN \n
ATOMIC GIN 40° FROM AtomicDistillers\n
Elephant Gin\n
PLATU LONDON DRY GIN 39°
"""
"link" => "https://www.facebook.com/2381232313223159570563/photos/a.238553749527504.54095.238123159570563/1036585816390956/?type=3"
"full_picture" => "https://scontent.xx.fbcdn.net/hphotos-xft1/v/t1.0-9/12235138_1032365824332445816390956_318234438793651778686071_n.jpg?oh=21fcf828fac0dd49e125b13028d57bfb&oe=56EB6A10"
]
在使用facebook结果的foreach时,我尝试遍历所有内容的数据字段但是我返回时出错:
Trying to get property of non-object (View: /var/www/web/elephantegin/htdocs/resources/views/socialApps/facebook.blade.php)
这是我使用的代码:
@foreach($results->data as $result)
<p>poops</p>
@endforeach
,或者这个:
@foreach($results as $result)
@foreach($result->data as $data)
<p>help</p>
@endforeach
@endforeach
我以前做过这个时间没问题。在我的控制器中使用json_decode之前我将它们推送到视图中。我怎样才能恰当地称这个foreach?
答案 0 :(得分:3)
如果我找对你,那么你有一个阵列,但试图获得财产。应该是这样的:
@foreach($results['data'] as $result)