1

我是 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 帖子和评论的开源搜索引擎!

4

1 回答 1

2

即使您没有在 http 请求中发送accept: gzip标头,您也需要解压缩它,因为所有响应都是 gzip'd

请参阅 如何在 PHP 中从 Stackoverflow API 读取 GZIP 版响应?

于 2011-12-21T17:05:48.190 回答