【发布时间】:2021-09-03 16:35:41
【问题描述】:
(注意:json 新手)我有一个 JSON 文件,其中包含图像 URL (https://pastebin.com/TavfuziF),代码如下:
<!DOCTYPE html>
<html>
<body>
<center>
<?php
$jdata = file_get_contents("cats-in-moviesnew.json");
//decode the retrieved json file into an array
$contents = json_decode($jdata, true);
echo
//create the table
"<table style border=3px solid black; ><tr><th>Producer</th><th>Director</th><th>Title</th><th>Year made</th><th>URL</th><th>Image</th><th>Poster URL</th></tr>";
//filling the table
foreach($contents as $record) {
echo
"<tr>
<td>" . $record["fields"]["produced_by"] . "</td>
<td>" . $record["fields"]["directed_by"] . "</td>
<td>" . $record["fields"]["title"] . "</td>
<td>" . $record["fields"]["year"] . "</td>
<td>" . $record["fields"]["url"] . "</td>
<td>" .
$record["fields"]["url_poster"]
. "</td>
<td>" . $record["fields"]["url_poster"] . "</td>
</tr>";
}
?>
</body>
</center>
</html>
我一直在试图弄清楚是否有可能在里面做类似 的事情(目前差距在表格填充位中)代码是否可能。我尝试了几件对我没有用的事情,我看到过一些关于将东西转换为 base64 的事情,但在我的水平上这对我来说非常复杂,我现在不知道还能做什么。任何帮助将不胜感激。
【问题讨论】:
-
是的,你可以这样做。如果它不起作用,请输出该值以确保它包含您期望的路径。看看你的报价。
-
请将 json 添加到问题中,而不是作为场外链接,否则当链接过期时,问题对未来的访问者没有帮助。您不需要发布整个内容,只需举几个示例项目来展示格式。
-
尝试
print_r($record);了解您的数据是什么样的,以及如何访问它。