将多字符串分成多行json

时间:2018-10-26 14:40:41

标签: json

我正在构建一个模板,供人们创建没有编码经验的测验。所以我正在尝试让人们更新json文件的最简单方法。我不知道如何将选项分成多行。任何帮助将不胜感激。

"1" : {
        "question": [
            "Pittsburgh is home to the first Cable Suspension Bridge.",
            "A: somewhat true", 
            "B: likely true",
            "C: always true",
            "D: completely false"
            ],


        "answer": "c"
    },

    "2" : {
        "question": [
            "Pittsburgh is home to the first Cable Suspension Bridge.",
            "A: somewhat true", 
            "B: likely true",
            "C: always true",
            "D: completely false"
            ],

        "answer": "c"
    },

    "3" : {
        "question": [
            "Pittsburgh is home to the first Cable Suspension Bridge.",
            "A: somewhat true", 
            "B: likely true",
            "C: always true",
            "D: completely false"
            ],

        "answer": "c"
    }, 

1 个答案:

答案 0 :(得分:0)

尝试使用此json结构

{
  "quiz":[{
    "question":"Pittsburgh is home to the first Cable Suspension Bridge.",
    "options":["somewhat true","likely true","always true","completely false"],
    "answer":"c"
  },
  {
    "question":"Pittsburgh is home to the first Cable Suspension Bridge.",
    "options":["somewhat true","likely true","always true","completely false"],
    "answer":"c"
  },
  {
    "question":"Pittsburgh is home to the first Cable Suspension Bridge.",
    "options":["somewhat true","likely true","always true","completely false"],
    "answer":"c"
  }]
}

它似乎很好用,因为它包含问题,答案和可用选项之间的分隔。如果您想维护多个测验,可以将此json结构包装到数组中。

{
  "quizzes":[{
    "quiz":[{
      "question":"Pittsburgh is home to the first Cable Suspension Bridge.",
      "options":["somewhat true","likely true","always true","completely false"],
      "answer":"c"
    },
    {
      "question":"Pittsburgh is home to the first Cable Suspension Bridge.",
      "options":["somewhat true","likely true","always true","completely false"],
      "answer":"c"
    },
    {
      "question":"Pittsburgh is home to the first Cable Suspension Bridge.",
      "options":["somewhat true","likely true","always true","completely false"],
      "answer":"c"
    }]
  }]
}