简体   繁体   中英

How to get json values from path inside vs code extension

Tried to get json values using below code but not working.This code is not working only inside my visual studio code extension: https://code.visualstudio.com/api/get-started/your-first-extension I do not know why it is not working inside vscode extension.Anyone can find the solution?

var file = JSON.parse(fs.readFileSync("c:\\xampp\\htdocs\\projects\\chemis\\package.json", "utf8"));
vscode.window.showInformationMessage(file);

The reason the original code does not work is you are passing the result of JSON.parse , which is an object, to window.showInformationMessage , which expects a string. In that situation, showInformationMessage silently does nothing.

To fix that, pass a string instead. As Arshad suggested, JSON.stringify is one way to do that.

In a comment, you mentioned getting "[object Object]". That is what happens if you stringify by calling Object.prototype.toString or by concatenating with a string (which implicitly calls toString).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM