如何在 PHP 中访问以 @ 开头的 stdClass 成员
我有一些已解码的 json 对象,其中一个属性以“@”开头,我无法使用 php 访问该元素,因为它会引发错误。
[offers] => stdClass Object
(
[@attributes] => stdClass Object
(
[id] => levaka0B8a
)
)
我将如何访问属性?
I have some json object that I decoded, and one of the attributes starts with an "@" and I can't access the element with php because it throws an error.
[offers] => stdClass Object
(
[@attributes] => stdClass Object
(
[id] => levaka0B8a
)
)
How would I go about accessing attributes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过字符串访问它:
或变量:
有关如何定义和使用变量的更多信息,请参阅以下文档:
You can access it by a string:
Or a variable:
For more information on how variables are defined and used, see the following docs:
你可以这样做:
You could do this:
尝试使用,
示例代码参考
Try to use,
Sample Code to Refer
下面是 ircmaxwell 或 Richard Tuin 的直接访问,但是您可以使用第二个参数 true 解码 JSON,并插入接收数组,这可能更容易访问
direct access is below from ircmaxwell or Richard Tuin, however you can decode JSON with second param true and recive array insted what could be an easier to access