包含以下内容的键的php json响应$
首先,谢谢你的阅读。这是我的密码 data.json包含以下内容的键的php json响应$,php,json,Php,Json,首先,谢谢你的阅读。这是我的密码 data.json { "$descriptor": "Testing Json", "$url": "NULL", "$totalResults": 1499, "$startIndex": 1, "$itemsPerPage": 1499, "$resources": [ { "$url": "NULL", "$uuid": "5e
{
"$descriptor": "Testing Json",
"$url": "NULL",
"$totalResults": 1499,
"$startIndex": 1,
"$itemsPerPage": 1499,
"$resources": [
{
"$url": "NULL",
"$uuid": "5e7b9312-52e5-4fe1-b3e4-633ca04c9764",
"$httpStatus": "OK"
}
]
}
index.php
<?php
$file_name = "data.json";
$file = json_decode(file_get_contents($file_name));
?>
<table class="table">
<thead>
<tr>
<th>Product Code</th>
<th>Product Name</th>
<th>Available Stock</th>
</tr>
</thead>
<br>
<tbody>
<?php
LINE 39 -> foreach($file->$resources as $mydata)
{
?>
<tr>
<td><?php echo $mydata->url; ?></td>
<td><?php echo $mydata->uuid; ?></td>
<td><?php echo $mydata->httpStatus; ?></td>
</tr>
<?php
};
?>
</tbody>
</table>
我只是想知道你是否能解释一下,我猜这是因为关键名字前面的美元符号。目前,我正在手动导入此文件,因为它将是来自api服务器的查询结果
如果是因为美元符号,我将如何消除它们
谢谢
Anthony,问题是由
$
引起的(您需要这些吗?)
$file->{'$resources'}
或者,如果解码为关联数组:
$file = json_decode(file_get_contents($file_name), true);
$file['$resources']
但是您的echo
语句也将访问一个数组:
echo $mydata['$url'];
非常感谢你,几个小时来你一直在逼我
echo $mydata['$url'];