【问题标题】:How to store the following JSON result into HTML table?如何将以下 JSON 结果存储到 HTML 表中?
【发布时间】:2018-06-10 10:49:11
【问题描述】:
    {
 "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"
      }
     }
     ]
    }

【问题讨论】:

  • 我试图制作一个 json_decode() 但得到该文本的错误。
  • 这是整个响应吗?
  • json中没有nil这个东西,必须为null
  • Stack Overflow 不是代码编写服务:请展示您尝试过的内容并描述您是如何陷入困境的。还请描述您希望将数据的哪些部分放入表格中。
  • 我需要内容中的 en

标签: php html json


【解决方案1】:

假设您希望在 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>

【讨论】:

    【解决方案2】:

    您可以使用 AppML 轻松做到这一点,here is a tutorial which will get you started quickly

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多