Node.js 如何在nodejs中读取json文件?
我的应用程序中有一个配置json文件Node.js 如何在nodejs中读取json文件?,node.js,json,Node.js,Json,我的应用程序中有一个配置json文件 { "Name":{ "Catgory":{ "Val":{ "Gaby": "122" }, "Batch":{ "Hede" : "86" } } }
{
"Name":{
"Catgory":{
"Val":{
"Gaby": "122"
},
"Batch":{
"Hede" : "86"
}
}
}
}
我有很多类似上面的配置。但是当我试着像下面这样读的时候,我做不到
I have imported the file as config in the current file. When I try to read as below I'm able to get the values.
config.Name.Catgory.Val
但是,如果我尝试动态地获取值,比如
configVal = "Val"
And if I try to call,
config.Name.Catgory.configVal I'm unable to read. Can anyone please help me with this?
您需要使用以动态访问值:
const-config={
“姓名”:{
“卡戈里”:{
“Val”:{
“加比”:“122”
},
“批次”:{
“赫德”:“86”
}
}
}
}
设configVal='Val';
console.log(config.Name.Catgory[configVal])代码>副本