我有一个看起来像这样的 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/