php-picasapi-json解码问题


php picasa api json decode problem

下面是我的代码,用于json解码picasa-api结果,但它总是Warning: Invalid argument supplied for foreach(),问题在哪里?谢谢

<?php
header('Content-type:text/html; charset=utf-8');
$url="http://picasaweb.google.com/data/feed/base/all?alt=json&kind=photo&access=public&filter=1&q=usa&imgor=landscape&max-results=50&hl=en";
$json = file_get_contents($url);
$data = json_decode($body, true);
foreach ($data['feed']['entry'] as $result){         
echo html_entity_decode($result->content->src, ENT_QUOTES, 'UTF-8');
echo html_entity_decode($result['updated']['$t'], ENT_QUOTES, 'UTF-8');
}
?>

json树

您使用了错误的变量:

$json = file_get_contents($url);
$data = json_decode($body, true);

它应该是$json而不是$body。

您使用了json_decode(,true),因此它将所有对象转换为关联数组。但在这里,您使用对象表示法来访问您的数据,这可能会导致另一个错误:

echo html_entity_decode($result->content->src, ENT_QUOTES, 'UTF-8');