我想在我的网站上显示我通过goole json api url收到的actvivites帖子结果,因此我使用了以下代码。但它没有显示结果。请指教
<?php
$jsonurl = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=%23fifa&alt=json&key={API KEY }";
$json = file_get_contents($jsonurl);
$json_output = json_encode($json);
//echo json_encode($json);
echo '<pre>';
//echo json_encode($json);
print_r($json_output);
echo '</pre>';
?>
<div class="datagrid ">
<?php
$json=array();
foreach ($json_output["data"] as $json_result) {
$json[] = array(
'value' => $json_result["title"],
'value' => $json_result["url"]
);
?>
<div ><table>
<tbody>
<TR>
<TD><h3><?php echo $json_result["title"];?></h3></TD>
<TD><h3><?php echo $json_result["url"];?></h3></TD>
</TR>
</tbody>
</table>
</div>
<?php
}
?>
</div>
答案 0 :(得分:1)
我可以在您的代码中指出一些内容。有些人肯定需要一些帮助。
你有这两行。
$json = file_get_contents($jsonurl);
$ json已经是一个json编码的字符串,我推测而不是以下行。你真的想把它解码成一个数组。
$json_output = json_encode($json);
如
$ json_output = json_decode($ json,true);
注意我使用了true参数来确保它被解码而不是std类变量数组。但我想这取决于你的代码中你想要什么。