【问题标题】:How to add photo and video to JSON quiz format?如何将照片和视频添加到 JSON 测验格式?
【发布时间】:2016-04-06 13:28:56
【问题描述】:

我正在用 JSON、jQuery 和 JavaScript 编写一个测验。

这是我的 JSON 问题:

"questions": [
        {             "q": "At a birthday party you counted 120 eyes. How many people were at the party?",
            "a": [
                {"option": "240",      "correct": false},
                {"option": "60",     "correct": true},
                {"option": "120",      "correct": false},
                {"option": "30",     "correct": false} // no comma here
            ], 

如何在问题中添加图片。这是正确的语法吗?

I have a folder called img
“q”: "At a birthday party you counted 120 eyes. How many people were at the party? <br> <br>"  + 

"<i** src="/i**/eyes.filename\">,   ** denotes mg read: image source 

另外,我如何将视频文件嵌入到 YouTube 中有链接的问题中?

【问题讨论】:

  • JSON 不了解图像或视频。您必须以接收者可以理解和使用的格式存储它。如果你是接收者,那就编造一些东西。
  • 这根本没有帮助。
  • 在什么方面没有帮助?我告诉你,没有“图像的 JSON 语法”之类的东西。你还想听什么?
  • 那么,如何在 js 中为测验添加图像或视频?
  • 您必须发明自己的格式。简单地将 HTML 放入字符串中(正如我认为您试图在示例中展示的那样)是一种简单而灵活的方法。但无论您选择什么,都由您来处理格式并用它做正确的事情。 JSON 没有任何魔力。

标签: javascript jquery json


【解决方案1】:

想通了。 这是您嵌入视频的方式:

{ 
        "q": "How would you weigh on the moon compared to earth?",
        "a": [
            {"option": "More",    "correct": false},
            {"option": "The same",     "correct": false}, 
            {"option": "Less",     "correct": true}, 
            {"option": "Need more info",     "correct": false} // no comma here
        ],
        "correct": "<p><span>Good Job!</span> Eat your cheesy pizza, fries, nachos, and fly to the moon to be a size zero or watch this video <br> <center> <iframe width=560 height=315 src=https://www.youtube.com/embed/OIzOCvxJcSE frameborder=0 allowfullscreen></iframe> </center> </p>",
        "incorrect": "<p><span>ERRRR!</span> Weight is determined by gravity, or how strongly gravity pulls on matter. Since the gravity on moon is weak compared to earth, you will weigh less.<br>Ready for a physics class? <center><iframe width=560 height=315 src=https://www.youtube.com/embed/OIzOCvxJcSE frameborder=0 allowfullscreen></iframe> </center> </p>" // no comma here
    } 

这是在 json 中添加图像的方式:

{ 
            "q": "What is the amount of matter in an object called? <br> <img src=https://cdn.vectorstock.com/i/composite/08,88/question-weighing-scale-vector-840888.jpg/>",
            "a": [
                {"option": "Weight",               "correct": false},
                {"option": "Density",   "correct": false},
                {"option": "Volume",               "correct": false},
                {"option": "Mass", "correct": true} // no comma here
            ],
            //Make it select any rather than all.
            "correct": "<p><span>Correct!</span> You like fancy words don't you?</p>",
            "incorrect": "<p><span>Fail.</span> Sorry. You need to brush up on your physics vocabulary. Weight is a measure of how strongly gravity pulls on that matter. Density describes how compact or concentrated something is, expressed as mass per unit volume. Volume is Volume is the amount of space that comprises a length, a width and a height, occupied by an object or a material.</p>" 
        }

【讨论】:

  • Biffen,很多人像我一样是 javascript 新手。我真的希望你能用示例代码解释你的答案。
  • @patty_mnouchkine 但是……没什么好解释的。再说一遍:JSON 不处理图像或视频。您可以将 HTML 放在 JSON 字符串中,但 JSON 仍然不知道它的含义。这就是为什么这个答案没有回答任何问题。如果您添加了使用 JSON 的代码,则可以。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 2014-09-08
  • 1970-01-01
  • 2015-06-05
相关资源
最近更新 更多