大家好,我在 NodeJs 中从本地 json 文件中获取项目作为值和键时遇到问题。
[
{
"question":"What is the first name of your best friend in high school?",
"answer":"U2FsdGVkX18/l/UF1DbqMp9ItOqgmmQIeVUlxqrb7vE="},
{
"question":"What was your childhood nickname?",
"answer":"U2FsdGVkX1+x14bgpnjr3UcvScBDbIOnP55vua2NvME="},
{
"question":"What is the name of the street you grew up in?",
"answer":"U2FsdGVkX1+pGkO/MRIP7oHym3Ynz/7n/fYuEt7fTFw="}]
这是本地 json 文件。 我如何获取问题和答案并将它们保存到不同的数组中。 提前致谢。
最佳答案
假设您的本地数据文件位于 data.json
中,您可以如下所示使用它。
var data = require('./data.json')
console.log(data[0]);
关于javascript - 在node js中从本地Json文件中获取值和键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47748831/