开发者

Forward slashes in stdClass object parsing JSON?

开发者 https://www.devze.com 2023-02-28 04:15 出处:网络
I\'m trying to access data within a JSON object I create using json_decode (based on a result from a URL). The response is:

I'm trying to access data within a JSON object I create using json_decode (based on a result from a URL). The response is:

stdClass Object
(
    [/guid/9202a8c04000641f8000000016f4c9cd] => stdClass Object
        (
            [code] => /api/status/ok
            [result] => stdClass Object
                (
                    [

..

How do I access the parameter "code"?

Tha开发者_C百科nks!


You can use this slightly more quirky syntax:

print $stdclass->{'/guid/9202a8c04000641f8000000016f4c9cd'}->code;

It's intended specifically for non-ascii attribute names. (There's also the variant with double quotes, which is useful for variable ->{"attr_$index"} attribute names.)


The other option would be to have json_decode create an associative array instead, by passing TRUE as second parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消