【问题标题】:Trying to display Json data from a web url into a table试图将 Json 数据从 web url 显示到表中
【发布时间】:2018-08-09 01:02:22
【问题描述】:
"crops": [
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Gulu", 
  "Price": "5002"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Busia", 
  "Price": "4889"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Kasese", 
  "Price": "5002"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Busia", 
  "Price": "4889"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Gulu", 
  "Price": "5002"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Kasese", 
  "Price": "4999"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Busia", 
  "Price": "4887"
}, 
{
  "Crop": "Red Beans", 
  "Date": "2018-Feb-28", 
  "Market": "Gulu", 
  "Price": "4999"
}
]}

【问题讨论】:

  • 除了json数据,您没有提供任何代码,也没有描述您遇到的任何问题/麻烦。
  • 恭喜,您已经展示了它!

标签: javascript html


【解决方案1】:

我就是这样解决的

<?php
            try{
                $url = 'the json url goes here'; // path to your JSON file
                $data = file_get_contents($url); // put the contents of the file into a variable
                $characters = json_decode($data);
                echo '<div class="panel-heading">
            <h3 align="center">Market Prices for ';  echo $characters[0]->Crop;
                echo '</h3>
        </div>';
                echo '<div class="panel-body">
            <table class="table table-striped table-hover border" style="font-family: cambria">
                <thead>
                <tr>
                    <th>Market</th>
                    <th>Date</th>
                    <th>Price</th>
                </tr>
                </thead>
                <tbody>';
                foreach ($characters as $character) {
                    echo '<tr>';
                    echo '<td>' . $character->Market . '</td>';
                    echo '<td>' . $character->Date . '</td>';
                    echo '<td>' . $character->Price . '</td>';
                    echo '</tr>';
                }

                echo '</tbody>
        </table>
    </div>';
            }
            catch (Exception $e){
                echo '<p align="center">No Internet Connection, please try again</p>';
            }
            ?>

【讨论】:

    【解决方案2】:

    您可以将此 json 并通过 json 的长度将其放入循环中,并将数据显示到表中。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 2021-08-18
    相关资源
    最近更新 更多