猿问

如何获得结果 (JSON PHP)

我有个问题。我怎样才能得到结果?


这是我的代码:


<?php 

$api_e = file_get_contents('https://omnihost.tech/dashboard/hosts/'.$slug.'/api_ftp');

$api = json_decode($api_e); ?>

<?php foreach($api as $file){ ?>

    <tr>

        <td>#</td>

        <td><?= $file; ?></td>

        <td>--</td>

    </tr>

<?php } ?>

我的 JSON 是:


{"data": [".","..",".editorconfig",".gitignore",".htaccess",".well-known","README.md","application","assets","cgi-bin","composer.json","contributing.md","index.php","license.txt","readme.rst","system"]}

错误:http : //prntscr.com/o98xau


墨色风雨
浏览 151回答 2
2回答

12345678_0001

您需要指定您需要打印的列,您可以尝试在下面打印文件名<td><?= $file['12']; ?></td>否则,您将循环打印数组中的所有数据,使用 2 个循环<?php foreach($api as $file) { ?><?php foreach($file as $i => $item) { ?><tr><td><?= $i; ?></td><td><?= $item; ?></td><td>--</td></tr><?php } ?><?php } ?>
随时随地看视频慕课网APP
我要回答