0

I need to convert JSON into a list using PHP, Tried code below but cannot make it work

$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>";
    }

And I want to show list as here (not as a table):

http://prntscr.com/no1479

2
  • Well, your code is explicitly outputting an HTML table. What other HTML did you want to output? Just a series of <span> elements? Something else? What did you try? Commented May 13, 2019 at 16:43
  • your $json is already a json why are you decoding it. also it does not contain stand.. Commented May 13, 2019 at 17:18

2 Answers 2

1

your all code is right but you can use stand class that is wrong your class is GetTickerJSONResult and so change the class stand to GetTickerJSONResult.

try this modified code..

 <?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>";
   }
  ?>
Sign up to request clarification or add additional context in comments.

Comments

0

It does not work because in $data->stand there is nothing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.