php访问json_decode数据

时间:2012-02-08 11:40:59

标签: php json

这是我的json对象

object(stdClass)#23 (2) { ["type"]=> string(4) "text" ["$t"]=> string(10) "cippalippa" } 

如何访问"text" ["$t"]

4 个答案:

答案 0 :(得分:5)

您需要使用以下语法:

$object->{'$t'}

此处提到的其他两个不起作用:

  • $object["\$t"] - 对象不是数组

  • $objetct->$t - 这会被解释为variable variable

      

    [...]如果您有$foo->$bar这样的表达式,则会检查$bar的本地范围,其值将用作$foo属性的名称

答案 1 :(得分:1)

你需要逃脱美元符号:

echo $object["\$t"];

答案 2 :(得分:1)

$object = json_decode({ ["type"]=> string(4) "text" ["$t"]=> string(10) "cippalippa" });

echo $objetct->$t;

这有效吗?

答案 3 :(得分:0)

解决了这个字符串:     $ obj-> { '$ T'}

相关问题