Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json数组PHP Youtube Api v2无法从$t接收字符串_Php_Json_Youtube - Fatal编程技术网

Json数组PHP Youtube Api v2无法从$t接收字符串

Json数组PHP Youtube Api v2无法从$t接收字符串,php,json,youtube,Php,Json,Youtube,我使用以下代码从youtube api v2获取频道json信息: $json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/users/lefloid?alt=json"),true); 然后尝试获取作者姓名 echo $json["entry"]["author"][0]["name"]["$t"]; 但是这个代码不起作用,所以我试着找出问题所在 $json = json_decode(file_g

我使用以下代码从youtube api v2获取频道json信息:

$json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/users/lefloid?alt=json"),true);
然后尝试获取作者姓名

echo $json["entry"]["author"][0]["name"]["$t"];
但是这个代码不起作用,所以我试着找出问题所在

$json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/users/lefloid?alt=json"),true)["entry"]["author"][0]["name"];
echo "<pre>";
print_r($json);
echo "</pre>";
但是这个代码后面的回音不起作用

<?php
    $json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/users/lefloid?alt=json"),true);
    print_r($json['entry']['author'][0]['name']['$t']);
?>

如何最终获得作者姓名?

以下代码将生成作者姓名

当你试着

echo$json[$t]

这将不起作用,因为当需要在$json[entry]['author'][0]['name']]前面加上$t时,您试图在数组的顶层访问$t

问题是$t被视为变量$t。您必须使用单引号而不是双引号:echo$json['$t'];
echo $json["$t"];
<?php
    $json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/users/lefloid?alt=json"),true);
    print_r($json['entry']['author'][0]['name']['$t']);
?>