首页 > 解决方案 > 显示来自数据库的 json

问题描述

我正在使用显示测验的 json 结构,但现在我不明白如何正确显示它请帮助我,我想从数据库中读取信息并显示在下面的 json 结构中,谢谢

[
  {
    "question_id" : 0,
    "question": "What is the original native name of Mount Rainier?",
    "answers": [
      {"id": 0, "text": "Tahoma"},
      {"id": 1, "text": "Shuksan"},
      {"id": 2, "text": "Stillaguamish"}

    ],
    "correct": 0
  },
  {
    "question_id" : 1,
        "question" : "Which image shows a close-up of the Nisqually Glacier?",
        "answers"  : [
            {"id"  : 0, "image" : "images/quizImages/glacier_01.jpg" },
            {"id"  : 1, "image" : "images/quizImages/glacier_02.jpg" },
            {"id"  : 2, "image" : "images/quizImages/glacier_03.jpg" },
            {"id"  : 3, "image" : "images/quizImages/glacier_04.jpg" }
        ],
        "correct"  : 3
    }
]

在此处输入图像描述

标签: phpmysqljson

解决方案


  1. 从数据库中获取您的数据并multidimensional array使用正在获取数据库的数据。

  2. 申请json_encode决赛array


推荐阅读