使用PHP将JSON转换为HTML行

使用PHP将JSON转换为HTML行,php,json,Php,Json,我需要使用PHP将JSON转换成一个列表,下面的代码已经尝试过了,但无法让它工作 $json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA"); $data = json_decode($json); if (count($data->stand)) { // Open the

我需要使用PHP将JSON转换成一个列表,下面的代码已经尝试过了,但无法让它工作

$json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA");
    $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->AvgPrice</td>";
            echo "<td>$stand->Description </td>";
            echo "</tr>";
        }

        // Close the table
        echo "</table>";
    }
我想在这里显示列表,而不是表格:


它不起作用,因为在$data->stand中没有任何内容。

您的所有代码都是正确的,但是您可以使用错误的stand类。您的类是GetTickerJSONResult,因此将类stand更改为GetTickerJSONResult

请尝试此修改后的代码

 <?PHP
     $set =json_decode($json);
      if (count($set->GetTickerJSONResult)) {
       echo "<table>";
       foreach ($set->GetTickerJSONResult as $idx => $stand) {

          echo "<tr>";
          echo "<td>$stand->AvgPrice</td>";
          echo "<td>$stand->Description </td>";
          echo "</tr>";
       }
        echo "</table>";
   }
  ?>

那么,您的代码将显式输出一个HTML表。您还想输出什么HTML?只是一系列的元素?还有别的吗?您尝试了什么?您的$json已经是json了,为什么要解码它。此外,它不包含展台。。