【发布时间】:2019-09-25 09:57:55
【问题描述】:
我遇到了问题。我在 python 烧瓶中使用 mcq 生成器。我的后端工作,但我的字体结尾有问题(我以前从未使用过 javascript)。
我的 python 生成器给了我一个这样的 json:
["{\"isMulti\": false, \"question\": {\"en\": \"What is the maximum number of IP addresses that can be assigned to hosts on a local subnet that uses the 255.255.255.224 subnet mask?\"}, \"answers\": [{\"en\": \"30\"}, {\"en\": \"14\"}, {\"en\": \"16\"}, {\"en\": \"15\"}], \"other\": {}}", "{\"isMulti\": false, \"question\": {\"en\": \"Which of this is not a class of IP address?\"}, \"answers\": [{\"en\": \"Class D\"}, {\"en\": \"Class F\"}, {\"en\": \"Class C\"}, {\"en\": \"Class E\"}], \"other\": {}}"]
我想要一个这样的 javascript 数组:
const myQuestions = [
{
question: en : "What is the maximum number of IP addresses that can be assigned to hosts on a local subnet that uses the 255.255.255.224 subnet mask?",
isMulti: "false",
answers: {
en: "30",
en: "14",
en: "16",
en: "15",
},
},
{
question: "question2",
isMulti: "true",
answers: {
en: "erer",
en: "wqrwerq",
en: "wrwrw"
},
}
]
我完全不知道这样做,我需要保留“en”信息。 “en”是翻译的关键。 可以是“fr”、“it”等
我的前端生成器使用这样的 n 数组:
const test = [
{
question: "Where i live?",
isMulti: "True",
answers: {
1: "Paris",
2: "Madrid",
3: "Bresil",
4: "Russia",
5: "Johanesbrug",
6: "Bruxelles"
},
}
];
【问题讨论】:
-
你不能有一个对象,其中多个键共享相同的名称,像这样:
{en: "30", en: "14", en: "16"}你可以有一个像这样的对象数组:[{en: "30"}, {en: "14"}, {en: "16"}]。
标签: javascript arrays json transform