如何将以下JSON结果存储到HTML表中?

时间:2017-12-30 07:46:23

标签: php html json

    {
 "total_count":3,
 "offset":2,
 "limit":2,
 "notifications":
    [
      {
    "id":"481a2734-6b7d-11e4-a6ea-4b53294fa671",
    "successful":15,
    "failed":1,
    "converted":3,
    "remaining":0,
    "queued_at":1415914655,
    "send_after":1415914655,
    "canceled": false,
    "url": "https://yourWebsiteToOpen.com",
    "data":null,
        "headings":{
      "en":"English and default langauge heading",
      "es":"Spanish language heading"
    },     
    "contents":{
      "en":"English and default content",
      "es":"Hola"
      }
     },
     {
    "id":"b6b326a8-40aa-13e5-b91b-bf8bc3fa26f7",
    "successful":5,
    "failed":2,
    "converted":0,
    "remaining":0,
    "queued_at":1415915123,
    "send_after":1415915123,
    "canceled": false,
    "url": nil,
    "data":{
      "foo":"bar",
      "your":"custom metadata"
    },
    "headings":{
      "en":"English and default langauge heading",
      "es":"Spanish language heading"
    },
    "contents":{
      "en":"English and default content",
      "es":"Hola"
      }
     }
     ]
    }

2 个答案:

答案 0 :(得分:0)

假设您想要在HTML表格中显示JSON数据,这是一个基本示例:

<?php

$json=<<<JSON
[
    {
        "name": "foo",
        "age": 23,
        "mood": "happy"
    },
    {
        "name": "bar",
        "age": 38,
        "mood": "sad"
    }
]
JSON;
$people = json_decode($json);
?>
<html>
<table>
    <thead>
        <tr><th>Name</th><th>Age</th><th>Mood</th></tr>
    </thead>
    <tbody>
    <?php foreach($people as $person): ?>
    <tr>
        <td><?= $person->name; ?></td>
        <td><?= $person->age; ?></td>
        <td><?= $person->mood; ?></td>
    </tr>
    <?php endforeach; ?>
    </tbody>
</table>
</html>

答案 1 :(得分:0)

您可以使用AppML here is a tutorial which will get you started quickly轻松完成。