jsonファイルの解析に助けが必要です。私は以下のファイルから「選択肢」を抽出する必要があります。Json parsing nodej
{"questions":[
{"question1": "Who is Prime Minister of the United Kingdom?", "choices": ["David Cameron", "Gordon Brown", "Winston Churchill", "Tony Blair"], "correctAnswer":0},
{"question": "North West", "choices": ["What is the name of Kim Kardashian's baby?", "What is the opposite of south?"], "correctAnswer":0},
{"question": "What's my favorite color?", "choices": ["Black", "Blue", "Magenta", "Red"], "correctAnswer":1},
{"question": "What's the meaning of life?", "choices": ["Too live happily", "To give to the greater good"], "correctAnswer":1}
]}
スクリプトをnodejs:
var fs = require("fs");
fs.readFile(__dirname + "/lib/questions.json", "Utf-8", function(err, data){
jsoncontent = JSON.parse(data);
//console.log(jsoncontent);
for (var i = 0; i < jsoncontent.length; ++i) {
//code
}
});
抽出するために、どのように?
'予想結果を示すという点でextract'を定義します。また、これを自分で解決しようとしてきたコードも表示してください。これはコード作成サービスではなく、あなたはあなたの試みを示すことが期待されます。 – charlietfl