【发布时间】:2011-12-21 15:44:55
【问题描述】:
我是 JSON 和 API 的新手,我想制作一个使用 StackOverflow API 的 PHP CLI 脚本。我给自己做了一把钥匙,这是我目前的代码:
<?php
//Call stack API .$key
$google_url = "http://api.stackoverflow.com/1.1/stats";
//Get and Store API results into a variable
$result = file_get_contents($google_url);
//$jsonArray = json_decode($result);
print_r($result);
//var_dump($jsonArray);
?>
但是 print_r($result); 返回一些奇怪的字符。看不懂,能不能给点资料?任何帮助将不胜感激。整个项目将是一个关于 StackOverflow 帖子和 cmets 的开源搜索引擎!
【问题讨论】:
-
您可能正在获取 gzip 压缩形式的数据。如果您使用 cURL 而不是 file_get_contents(),您可以调整选项以便它为您处理 gzip。
-
非常感谢这确实是问题
标签: php json api command-line-interface stackexchange-api