gpt4 book ai didi

php - 当标识符以@符号开头时如何访问php中的对象?

转载 作者:行者123 更新时间:2023-12-01 08:23:31 24 4
gpt4 key购买 nike

我有一个看起来像这样的 json 对象:

{#119130 ▼
+"@id": "1EBEF5DA"
+"@name": "The"
+"@renewal": "xxxxx"
+"@languages": "Eng"
}

当标识符以 @ 开头时,如何访问 php 中的 JSON 数据象征?

例如尝试使用 $var->@id 访问它导致错误:
Parse error: syntax error, unexpected '@', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'

我试过 $var->id但它会导致 Undefined Property .

最佳答案

用这个:

$a = '{"@id":"123","@idx":"2232"}';
$b = json_decode($a);
print_r($b);
echo $b->{'@id'};

关于php - 当标识符以@符号开头时如何访问php中的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45648360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com