【发布时间】:2013-03-01 13:08:01
【问题描述】:
我有一个 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对象?
-
你绝对需要知道 JSON 字符串的结构。没有办法猜测!
-
@MatteoTassinari Vicario 查看更新后的问题。
-
我建议您从浏览器的“查看/源代码”菜单中检查
print_r()的输出,以免格式混乱。否则,您会不必要地难以看到它。另外,如果你不打算发布 JSON,那么所有对 JSON 的引用都是无关紧要的:你只有一个 PHP 数组,它来自哪里并不重要。
标签: php javascript json email