如何获得结果(JSON PHP)

I have a problem. How can I get the result?

Here is my code:

<?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 } ?>

My JSON is:

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

Error: http://prntscr.com/o98xau

json_decode can receive two parameters, the first the json and the second a Boolean value that would indicate, if true, that the object will be decoded as an array. You can try to apply the second parameter in the function to be able to iterate correctly with the foreach that you have already done.

json_decode($api_e, true);

assuming that what is stored in the variable $api_e is something like this:

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

this sholud work:

<?php
$api = json_decode($api_e, true);
?>
<?php foreach($api["data"] as $file){ ?>
    <tr>
        <td>#</td>
        <td><?= $file; ?></td>
        <td>--</td>
    </tr>
<?php } ?>

if it does not work, your url is probably wrong or it is not getting a correct value with the file_get_contents (), you should check that.

You need to specify which column you need to print, you can try below to print filename

<td><?= $file['12']; ?></td>

Or else you are loop to print all data in the array use 2 loops

<?php foreach($api as $file) { ?>
<?php foreach($file as $i => $item) { ?>
<tr>
<td><?= $i; ?></td>
<td><?= $item; ?></td>
<td>--</td>
</tr>
<?php } ?>
<?php } ?>