1. 程式人生 > >vscode中讀取json檔案settings.json

vscode中讀取json檔案settings.json

讀取檔案的內容:
在這裡插入圖片描述

讀取檔案的方法:

var settingsPath = process.env.AppData + "\\Code\\User\\settings.json";

var allConfigJson = JSON.parse(fs.readFileSync(settingsPath).toString());

if (allConfigJson["workbench.colorTheme"] != undefined) {
    themeColor = allConfigJson["workbench.colorTheme"].toString().trim();
    
    if (themeColor.indexOf("Light") != -1) {
        MyDTSInfoWebview.htmlFilePath = "\\media\\ui\\myDTSInfoLight.html";
    } else if (themeColor.indexOf("Dark") != -1) {
        MyDTSInfoWebview.htmlFilePath = "\\media\\ui\\myDTSInfo.html";
    }