-2

I want to parse this json in php and show it in a table.

{"Files":[{"name":"Tester","Dir":true,"path":"\/stor\/ok"},{"name":"self","Dir":true,"path":"\/stor\/nok"}]}
0

2 Answers 2

3

You can use simple foreach loop like this.

Code

<?php

$json = '{"Files":[{"name":"Tester","Dir":true,"path":"/stor/ok"},{"name":"self","Dir":true,"path":"/stor/nok"}]}';
$json = json_decode($json, true);

?>
<!DOCTYPE html>
<html>
<body>
    <table border="1">
        <tr><td>name</td><td>Dir</td><td>path</td></tr>
        <?php foreach ($json["Files"] as $k => $v): ?>
            <tr>
                <td><?php echo htmlspecialchars($v["name"]); ?></td>
                <td><?php echo htmlspecialchars($v["Dir"]); ?></td>
                <td><?php echo htmlspecialchars($v["path"]); ?></td>
            </tr>
        <?php endforeach; ?>
    </table>
</body>
</html>

Result

screenshot result

Sign up to request clarification or add additional context in comments.

Comments

1

I created you some little code example. You decode your string to json array. Thereafter you can parse the Files array with a foreach loop. Then in the foreach you can output/ save your values. In this case I output the name.

$string = '{"Files":[{"name":"Tester","Dir":true,"path":"\/stor\/ok"},{"name":"self","Dir":true,"path":"\/stor\/nok"}]}';

$string = json_decode($string, true);

if ($string != null)
{
    foreach ($string['Files'] as $values)
    {
        echo $values['name'];
        echo "\n";
    }
}

Output:

Tester
self

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.