Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73935

How can I read thosess JSON data an put in table [duplicate]

$
0
0

This question already has an answer here:

I'm trying to print a JSON file in a HTML Table with PHP

Here is my JSON structure (i have intentionnaly mask some informations)

[
{"ip": "8.8.8.8", 
 "networkId": "XXXXXX", 
 "serial": "XXXXXXXX", 
    "timeSeries": [{
         "latencyMs": 1.5, 
         "lossPercent": 0.0, 
         "ts": "2020-01-10T17:23:25Z"},
     {
         "latencyMs": 1.5, 
         "lossPercent": 0.0, 
         "ts": "2020-01-10T17:24:25Z"}, 
     {
         "latencyMs": 1.5, 
         "lossPercent": 0.0, 
         "ts": "2020-01-10T17:25:25Z"},
     {
         "latencyMs": 1.5,
         "lossPercent": 0.0, 
         "ts": "2020-01-10T17:26:25Z"}, 
     {
         "latencyMs": 1.5, 
         "lossPercent": 0.0, 
         "ts": "2020-01-10T17:27:25Z"}], 
 "uplink": "wan1"}]

Here is my actual PHP code :

<?php
$json = file_get_contents('data.json');
$data =  json_decode($json);

echo '<table>';
echo '<th>';
echo '<tr>Appliance Serial</tr>';
echo '<tr>Network Id</tr>';
echo '<tr>Destination</tr>';
echo '<tr>uplink</tr>';
echo '</th>';
echo '<tbody>';
foreach($data as $item)
{
    echo '<tr>';
    echo '<td>'.$item->serial.'</td>';
    echo '<td>'.$item->networkId.'</td>';
    echo '<td>'.$item->ip.'</td>';
    echo '<td>'.$item->uplink.'</td>';
    echo '<td>'.$item->timeSeries.'</td>';
    echo '</tr>';
}
echo '</tbody>';
echo '</table>';
?>

I'm not able to print the 'timeSeries' section because it's an array :

Notice: Array to string conversion in C:\xampp\htdocs\dev\index.php on line 35

XXXXX XXXXX 8.8.8.8 wan1 Array

I don't found any solution to do that any ideas ?

I would like to have someting like this :

Table


Viewing all articles
Browse latest Browse all 73935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>