需要帮助解析json文件。我需要从下面的文件中提取'选择'。Json解析nodejs
{"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