0
我正在爲考試練習構建移動應用程序。我需要一個API端點來提供考試細節和問題。我需要幫助在sails.js中構建我的數據。我有這個來自Firebase的JSON結構。sailsjs考試應用程序模型結構API
端點GET操作應該返回此:
{
"8h9iuhiuhi89h98h": {
"exam": "waec",
"year": "1990",
"subject": "chemistry",
"question": "Which of these is not an acid",
"answers": [
{
option: "NaCl",
isValid: true
},
{
option: "H<sub>2</sub>SO<sub>4</sub>",
isValid: false
},
{
option: "H<sub>3</sub>",
isValid: false
},
{
option: "HCl",
isValid: false
}
]
},
"8h9iuhiuhi89h98h": {
"exam": "waec",
"year": "1990",
"subject": "chemistry",
"question": "Which of these is not an acid",
"answers": [
{
option: "NaCl",
isValid: true
},
{
option: "H<sub>2</sub>SO<sub>4</sub>",
isValid: false
},
{
option: "H<sub>3</sub>",
isValid: false
},
{
option: "HCl",
isValid: false
}
]
},
"8h9iuhiuhi89h98h": {
"exam": "waec",
"year": "1990",
"subject": "chemistry",
"question": "Which of these is not an acid",
"answers": [
{
option: "NaCl",
isValid: true
},
{
option: "H<sub>2</sub>SO<sub>4</sub>",
isValid: false
},
{
option: "H<sub>3</sub>",
isValid: false
},
{
option: "HCl",
isValid: false
}
]
},
"8h9iuhiuhi89h98h": {
"exam": "waec",
"year": "1990",
"subject": "chemistry",
"question": "Which of these is not an acid",
"answers": [
{
option: "NaCl",
isValid: true
},
{
option: "H<sub>2</sub>SO<sub>4</sub>",
isValid: false
},
{
option: "H<sub>3</sub>",
isValid: false
},
{
option: "HCl",
isValid: false
}
]
}
}
其中WAEC是考試,是1990年的一年,和化學是主體。
http://someappurl.com/api/exam/{exam}/{year}/{subject}
我已經使用sails generate命令生成了API。但我不知道如何構建和查詢我的數據。我如何構建我的模式? 我有這樣的風帆模型結構
attributes: {
exams: {
exam_name: 'string',
years: {
exam_year: 'string',
subjects:[
{
subject_name: 'string',
questions: [
{
serial_no: 'string',
text: 'string',
answers:[
{
option: 'string',
is_valid: 'boolean'
}
]
}
]
}
]
}
}
}
你的JSON爲n無效。你有重複的鍵和大量的元素名稱不包含在雙引號。請更正此問題,然後通過格式化程序運行它,否則人們應該如何閱讀它? –