【发布时间】:2018-08-24 04:36:16
【问题描述】:
我曾尝试使用 php 来获取 Github 版本的 tag_name,但徒劳无功。 链接是Latest Release
<?php
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)');
$json =file_get_contents("https://api.github.com/repos/carry0987/Messageboard/releases/latest") ;
$myArray = json_decode($json);
foreach( $myArray as $key => $value ){
echo $key."\t=>\t".$value."\n";
}
?>
【问题讨论】:
-
您正在拉回一个对象,请尝试将第二个
json_decode参数设置为true以将其作为数组返回。 -
@JonStirling 喜欢这样吗? json_decode($json,true);
-
是的,就是这样。
-
为什么不用
$myArray->tag_name为什么人们那么害怕物体。也许将$myArray重命名为$myObj更准确 -
@RiggsFolly 我是 php 新手...我将重新编辑我的代码,让它变得更好