JSON values into HTML table

前端 未结 3 1346
情话喂你
情话喂你 2021-02-10 15:37

I have a table.html, data.php and json.csv within the same folder.

data.php is doing fopen(\"json.csv\",\"r\") to read f

3条回答
  •  粉色の甜心
    2021-02-10 16:04

    You just need json_decode and some iteration

    http://php.net/manual/en/function.json-decode.php

    I'll show you a very simplistic way to do the PHP. You don't tell anything about the JSON, so I'm assuming its flat (not nested). I think you might want to alter the client side stuff too. Make txtJSON into an empty div, which will be filled with the output from the PHP.

    $file = $fopen("json.csv", 'r');
    $fileText = fread($file, filesize($file));
    $arr = json_decode($fileText, true); //i prefer associative array in this context
    
    echo "";
    foreach($arr as $k=>$v)
        echo "";
    echo "
    $k$v
    ";

    If your JSON is not flat and simple, what would you like the resulting table to look like?

提交回复
热议问题