Json从URL无效解码

时间:2015-12-27 23:48:29

标签: php json

我正在尝试使用mojang api从用户名中检索用户Minecraft UUID这就是我所拥有的:

//Get Player UUID from name
$uuid = "Error obtaining uuid";
$json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' + $_GET['name']);
$obj = json_decode($json);
$uuid = $obj->id;

变量$uuid包含null,我不知道我做错了什么我确保通过转到$_GET设置player.php/?name=_Joosh参数但仍然没有?

1 个答案:

答案 0 :(得分:1)

您必须使用//Get Player UUID from name $name = 'john'; $uuid = "Error obtaining uuid"; // Tested with simple variable // $json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $name); $json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $_GET['name']); $obj = json_decode($json); $uuid = $obj->id; print $uuid; opearator进行连接而不是加号。请尝试以下代码段。

array_equal