本文介绍了github api在json的末尾返回1.这是一个错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用curl http://github.com/api/v2/json/用户/显示/用户名github的用户api返回以下内容:
using curl http://github.com/api/v2/json/user/show/usernamegithub's user api returns this:
...,"login":"myUsername","email":"[email protected]"}}**1**
为什么json之后有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);
}
尝试
echo getGithub();
但是由于末尾有1,所以我必须
but since there's the 1 on the end, I have to
echo rtrim(getGithub(), "1");
推荐答案
设置CURLOPT_RETURNTRANSFER
. curl_exec()当前返回true,然后回显,并显示为1.
Set CURLOPT_RETURNTRANSFER
. curl_exec() is currently returning true, which you're then echoing, which gets printed as 1.
这篇关于github api在json的末尾返回1.这是一个错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!