Forward slashes in stdClass object parsing JSON?
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.
精彩评论