• <legend id='1Zbf3'><style id='1Zbf3'><dir id='1Zbf3'><q id='1Zbf3'></q></dir></style></legend>

    <i id='1Zbf3'><tr id='1Zbf3'><dt id='1Zbf3'><q id='1Zbf3'><span id='1Zbf3'><b id='1Zbf3'><form id='1Zbf3'><ins id='1Zbf3'></ins><ul id='1Zbf3'></ul><sub id='1Zbf3'></sub></form><legend id='1Zbf3'></legend><bdo id='1Zbf3'><pre id='1Zbf3'><center id='1Zbf3'></center></pre></bdo></b><th id='1Zbf3'></th></span></q></dt></tr></i><div id='1Zbf3'><tfoot id='1Zbf3'></tfoot><dl id='1Zbf3'><fieldset id='1Zbf3'></fieldset></dl></div>

    <small id='1Zbf3'></small><noframes id='1Zbf3'>

  • <tfoot id='1Zbf3'></tfoot>

        • <bdo id='1Zbf3'></bdo><ul id='1Zbf3'></ul>

        如何使用 PHP 将 JSON 解析为 html 表?

        时间:2023-10-04
          1. <legend id='XB87M'><style id='XB87M'><dir id='XB87M'><q id='XB87M'></q></dir></style></legend>
              <tfoot id='XB87M'></tfoot>
              <i id='XB87M'><tr id='XB87M'><dt id='XB87M'><q id='XB87M'><span id='XB87M'><b id='XB87M'><form id='XB87M'><ins id='XB87M'></ins><ul id='XB87M'></ul><sub id='XB87M'></sub></form><legend id='XB87M'></legend><bdo id='XB87M'><pre id='XB87M'><center id='XB87M'></center></pre></bdo></b><th id='XB87M'></th></span></q></dt></tr></i><div id='XB87M'><tfoot id='XB87M'></tfoot><dl id='XB87M'><fieldset id='XB87M'></fieldset></dl></div>

                <tbody id='XB87M'></tbody>

              • <bdo id='XB87M'></bdo><ul id='XB87M'></ul>

                  <small id='XB87M'></small><noframes id='XB87M'>

                1. 本文介绍了如何使用 PHP 将 JSON 解析为 html 表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我必须在我的网站上找到一张桌子.并且必须从"http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373"我尝试了很多东西,但没有任何效果......

                  I have to get a table in my website. And have to get the data for this table from "http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373" I've tried a lot of thing but nothing works....

                   <!DOCTYPE html>
                    <html>
                     <head>
                      <script type="text/javascript" 
                         src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                     </head>
                     <body>
                      <?php
                      $json=file_get_contents("http://west.basketball.nl/db/json
                      /stand.pl?szn_Naam=2014-2015&cmp_ID=373");
                              $data =  json_decode($json);
                  
                          if (count($data)) {
                              // Open the table
                              echo "<table>";
                  
                              // Cycle through the array
                              foreach ($data as $stand) {
                  
                                  // Output a row
                                  echo "<tr>";
                                  echo "<td>$afko</td>";
                                  echo "<td>$positie</td>";
                                  echo "</tr>";
                              }
                  
                              // Close the table
                              echo "</table>";
                          }
                      ?>
                    </body>
                  </html>
                  

                  推荐答案

                  从外部获取数据时首先要做的就是了解返回的内容.

                  Ok first thing to do when getting data from an external source is to understand what is being returned.

                  也是这样

                  <?php
                  $json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
                  $data =  json_decode($json);
                  
                  print_r($data);
                  

                  结果:

                  stdClass Object
                  (
                      [stand] => Array
                          (
                              [0] => stdClass Object
                                  (
                                      [afko] => Risne Stars HS 1
                                      [ID] => 2091
                                      [status] => Actief
                                      [gespeeld] => 3
                                      [percentage] => 100.0
                                      [punten] => 6
                                      [tegenscore] => 149
                                      [eigenscore] => 191
                                      [datum] => 2014-10-05
                                      [saldo] => 42
                                      [team] => Risne Stars Heren 1
                                      [positie] => 1
                                  )
                  
                              [1] => stdClass Object
                                  (
                                      [afko] => D.B.V. Arriba HS 2
                                      [ID] => 1813
                                      [status] => Actief
                                      [gespeeld] => 2
                                      [percentage] => 0.0
                                      [punten] => 0
                                      [tegenscore] => 116
                                      [eigenscore] => 102
                                      [datum] => 2014-10-05
                                      [saldo] => -14
                                      [team] => D.B.V. Arriba Heren 2
                                      [positie] => 10
                                  )
                  
                              [2] => stdClass Object
                                  (
                                      [afko] => The Valley Bucketeers HS 2
                                      [ID] => 2430
                                      [status] => Actief
                                      [gespeeld] => 2
                                      [percentage] => 0.0
                                      [punten] => 0
                                      [tegenscore] => 177
                                      [eigenscore] => 70
                                      [datum] => 2014-10-05
                                      [saldo] => -107
                                      [team] => The Valley Bucketeers Heren 2
                                      [positie] => 11
                                  )
                  
                              [3] => stdClass Object
                                  (
                                      [afko] => Uitsmijters HS 2
                                      [ID] => 2143
                                      [status] => Actief
                                      [gespeeld] => 2
                                      [percentage] => 100.0
                                      [punten] => 4
                                      [tegenscore] => 79
                                      [eigenscore] => 161
                                      [datum] => 2014-10-05
                                      [saldo] => 82
                                      [team] => Uitsmijters Heren 2
                                      [positie] => 2
                                  )
                  
                              [4] => stdClass Object
                                  (
                                      [afko] => Picker Reds HS 1
                                      [ID] => 2056
                                      [status] => Actief
                                      [gespeeld] => 3
                                      [percentage] => 66.7
                                      [punten] => 4
                                      [tegenscore] => 193
                                      [eigenscore] => 184
                                      [datum] => 2014-10-05
                                      [saldo] => -9
                                      [team] => Picker Reds Heren 1
                                      [positie] => 3
                                  )
                  
                              [5] => stdClass Object
                                  (
                                      [afko] => Peatminers HS 2
                                      [ID] => 6247
                                      [status] => Actief
                                      [gespeeld] => 1
                                      [percentage] => 100.0
                                      [punten] => 2
                                      [tegenscore] => 36
                                      [eigenscore] => 64
                                      [datum] => 2014-10-05
                                      [saldo] => 28
                                      [team] => Peatminers Heren 2
                                      [positie] => 4
                                  )
                  
                              [6] => stdClass Object
                                  (
                                      [afko] => Jolly Jumpers HS 1
                                      [ID] => 1994
                                      [status] => Actief
                                      [gespeeld] => 2
                                      [percentage] => 50.0
                                      [punten] => 2
                                      [tegenscore] => 103
                                      [eigenscore] => 119
                                      [datum] => 2014-10-05
                                      [saldo] => 16
                                      [team] => Jolly Jumpers Heren 1
                                      [positie] => 5
                                  )
                  
                              [7] => stdClass Object
                                  (
                                      [afko] => TONEGO '65 HS 2
                                      [ID] => 2120
                                      [status] => Actief
                                      [gespeeld] => 2
                                      [percentage] => 50.0
                                      [punten] => 2
                                      [tegenscore] => 107
                                      [eigenscore] => 122
                                      [datum] => 2014-10-05
                                      [saldo] => 15
                                      [team] => TONEGO '65 Heren 2
                                      [positie] => 6
                                  )
                  
                              [8] => stdClass Object
                                  (
                                      [afko] => Amical HS 2
                                      [ID] => 1791
                                      [status] => Actief
                                      [gespeeld] => 3
                                      [percentage] => 33.3
                                      [punten] => 2
                                      [tegenscore] => 180
                                      [eigenscore] => 195
                                      [datum] => 2014-10-05
                                      [saldo] => 15
                                      [team] => Amical Heren 2
                                      [positie] => 7
                                  )
                  
                              [9] => stdClass Object
                                  (
                                      [afko] => S.V.Z.W. HS 2
                                      [ID] => 5526
                                      [status] => Actief
                                      [gespeeld] => 3
                                      [percentage] => 33.3
                                      [punten] => 2
                                      [tegenscore] => 174
                                      [eigenscore] => 151
                                      [datum] => 2014-10-05
                                      [saldo] => -23
                                      [team] => S.V.Z.W. Heren 2
                                      [positie] => 8
                                  )
                  
                              [10] => stdClass Object
                                  (
                                      [afko] => Twente Buzzards HS 3
                                      [ID] => 2294
                                      [status] => Actief
                                      [gespeeld] => 3
                                      [percentage] => 33.3
                                      [punten] => 2
                                      [tegenscore] => 196
                                      [eigenscore] => 151
                                      [datum] => 2014-10-05
                                      [saldo] => -45
                                      [team] => Twente Buzzards Heren 3
                                      [positie] => 9
                                  )
                  
                          )
                  
                      [nummer] => OHS2C
                      [version] => 1.0
                      [aantal_teams] => 11
                      [id] => 373
                      [seizoen] => 2014-2015
                      [naam] => Oost Afdeling Heren Senioren 2e klasse C
                      [gewijzigd] => 2014-10-05 18:34:25
                  )
                  

                  所以现在您知道您正在处理 OBJECT 而不是标量值或数组.

                  So now you know you are dealing with an OBJECT and not scalar values or an array.

                  所以试试这个代码:-

                  <?php
                      $json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
                      $data =  json_decode($json);
                  
                      if (count($data->stand)) {
                          // Open the table
                          echo "<table>";
                  
                          // Cycle through the array
                          foreach ($data->stand as $idx => $stand) {
                  
                              // Output a row
                              echo "<tr>";
                              echo "<td>$stand->afko</td>";
                              echo "<td>$stand->positie</td>";
                              echo "</tr>";
                          }
                  
                          // Close the table
                          echo "</table>";
                      }
                  ?>
                  

                  这篇关于如何使用 PHP 将 JSON 解析为 html 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:无法安装 Vagrant box Laravel Homestead 下一篇:用 PHP 创建表并从 MySQL 填充

                  相关文章

                  最新文章

                2. <legend id='AADFd'><style id='AADFd'><dir id='AADFd'><q id='AADFd'></q></dir></style></legend>

                3. <i id='AADFd'><tr id='AADFd'><dt id='AADFd'><q id='AADFd'><span id='AADFd'><b id='AADFd'><form id='AADFd'><ins id='AADFd'></ins><ul id='AADFd'></ul><sub id='AADFd'></sub></form><legend id='AADFd'></legend><bdo id='AADFd'><pre id='AADFd'><center id='AADFd'></center></pre></bdo></b><th id='AADFd'></th></span></q></dt></tr></i><div id='AADFd'><tfoot id='AADFd'></tfoot><dl id='AADFd'><fieldset id='AADFd'></fieldset></dl></div>
                  <tfoot id='AADFd'></tfoot>
                    • <bdo id='AADFd'></bdo><ul id='AADFd'></ul>
                  1. <small id='AADFd'></small><noframes id='AADFd'>