Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
PHP解码JSON得到uname?_Php_Json - Fatal编程技术网

PHP解码JSON得到uname?

PHP解码JSON得到uname?,php,json,Php,Json,如何将此JSON中的uname值转换为PHP变量?通过我的页面使用 { "token": "iutiutiut-0jjjjj0-97987g", "auth": { "id": 1, "app_id": 1, "user": { "uname": "foo", "role": "member"

如何将此JSON中的uname值转换为PHP变量?通过我的页面使用

    {
        "token": "iutiutiut-0jjjjj0-97987g",
        "auth": {
            "id": 1,
            "app_id": 1,
            "user": {
                "uname": "foo",  
                "role": "member"
            }
    }
}
出于某种原因,我无法得到它,我在谷歌上找不到类似的例子,或者我没有正确地调用它


您能告诉我正确的术语吗?这样我也知道了。谢谢您尝试解码JSON。PHP有一个内置函数,它的名字很贴切。假设您的JSON是一个字符串$JSON_字符串,下面是您将如何解码它:

$obj = json_decode($json_string);
$uname = $obj->auth->user->uname;
或者,如果您喜欢数组语法,请使用json_decode中的第二个参数:


你对哪一部分有问题?解码JSON,或将数据发布到PHP?很抱歉解码。谢谢你,我真的看到了我的错误,我把它设置为编码JSON_encode$cexecute,JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT;这就是我们扔掉它的原因。非常感谢。
$arr = json_decode($json_string, true);
$uname = $obj['auth']['user']['uname'];