问题
using curl http://github.com/api/v2/json/user/show/username github's user api returns this:
...,"login":"myUsername","email":"myEmail@test.com"}}**1**
why is there a 1 after the json? Is that a mistake on their part, or is that supposed to be used for something?
<?php
function getGithub($url="user/show/username") {
$github = curl_init();
curl_setopt($github, CURLOPT_URL, "http://github.com/api/v2/json/". $url);
return curl_exec($github);
}
trying to
echo getGithub();
but since there's the 1 on the end, I have to
echo rtrim(getGithub(), "1");
回答1:
Set CURLOPT_RETURNTRANSFER. curl_exec() is currently returning true, which you're then echoing, which gets printed as 1.
来源:https://stackoverflow.com/questions/5821595/github-api-returning-1-at-the-end-of-json-is-this-a-mistake