0

我已经对来自 CNET API 的结果进行 JSON 解码并得到以下结果(在 var_dump() 之后):

object(stdClass)#4 (35) { 
    ["Summary"]=> object(stdClass)#5 (1) { 
        ["$"]=> string(89) "Record keystrokes, visited web sites, and screenshots of all PC
activity in stealth mode."
    }
    ["Requirements"]=> object(stdClass)#6 (0) {}
    ["CNETContentIds"]=> object(stdClass)#7 (0) { } 
    ["CleverBridgeUrl"]=> object(stdClass)#8 (0) { } 
    ["BuyNowUrl"]=> object(stdClass)#9 (1) {
        ["@type"]=> string(0) "" 
    }
    ...

如何访问名为“$”的变量中的 89 个字符的字符串?

我试过这个:

$object->Summary->$

但是我的编辑给了我一个错误。

我知道,通过反复试验,您可以将 '->' 串在一起来访问嵌套对象,但一个成员被命名为 $?

即使转义 $ 也不起作用:

$object->Summary->\$
4

2 回答 2

2

您可以使用方括号访问非标准属性名称{}

$object->Summary->{'$'}
于 2013-04-29T09:50:08.410 回答
0

尝试;

$object->Summary->{'$'}

甚至

$object->{'Summary'}->{'$'}
于 2013-04-29T09:49:24.233 回答