簡體   English   中英

PHP:從解碼的JSON對象打印特殊值

[英]PHP: Print special value from decoded JSON Object

我有一個JSON對象,我使用php函數json_decode對其進行了解碼。 不,我想從對象中打印一個特殊值:

echo $user[0]['mail'][0];

我的問題是我得到這樣的回報:

string(19) "example@hotmail.com"

我用ldap_search結果填充了json對象。 當我使用js解析JSON並打印出電子郵件時,它看起來不錯,但使用PHP則不然。

編輯:

array(2) { 
    ["count"]=>  int(1)  [0]=>  array(10) {   
        ["mail"]=>    array(2) {
            ["count"]=>      int(1)      [0]=>      string(23) "example@hotmail.com"
        } [0]=>    string(4) "mail"
        ["givenname"]=>    array(2) { 
            ["count"]=>      int(1)      [0]=>      string(5) "sylnois"
        } [1]=>    string(9) "givenname"
        ["sn"]=>    array(2) {
            ["count"]=>      int(1)      [0]=>      string(7) "bla"
        }    [2]=>    string(2) "sn"
        ["ou"]=>    array(2) {
            ["count"]=>      int(1)      [0]=>      string(4) "ZH"
        }    [3]=>    string(2) "ou"
        ["count"]=>    int(4)    ["dn"]=>    string(24) "SOME_DN"  }}
$json = '{"user_name":"admin","0":{"email":{"0":"admin@gmail.com"}},"count":5}';


$user = json_decode($json,true);

echo $user[0]['email'][0];

 Rusult : admin@gmail.com

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM