我有以下具有以下结构的json数据
{
"page": 0,
"items": 43,
"total": 43,
"incentiveItems": {
"incentiveItem": [
{
"@id": "1111",
"name": "...",
"program": {
"@id": "6765",
"$": "NAME"
},
"admedia": {
"admediumItem": {
...
以及更多,要解析php中的数据我做了一个简单的foreach ...
$obj = json_decode($jsonData);
echo $obj->items;
echo '<table><tr><td>Nome</td><td>Descrizione</td><td>Codice</td></tr>';
foreach($obj->incentiveItems->incentiveItem as $programma ) {
所以,问题是我无法调用“$”:“NAME”值,因为我使用(例如)
$programma->program->$
$programma->program['$']
$obj->incentiveItems->incentiveItem->program->$ or ['$']
崩溃
和@id字段相同。
有人能帮帮我吗?感谢答案 0 :(得分:0)
将json解码为关联数组:
$obj = json_decode($jsonData, true);
echo $obj['items'];
echo '<table><tr><td>Nome</td><td>Descrizione</td><td>Codice</td></tr>';
foreach($obj['incentiveItems']['incentiveItem'] as $programma ) {
echo $programma['@id'];
答案 1 :(得分:0)
我相信您可以使用单引号和大括号来访问它
$obj->incentiveItems->incentiveItem->program->{'$'}
$obj->incentiveItems->incentiveItem->program->{'@id'}