现在我正在浏览 gulpfile 中的代码,并将其发送到适当的位置。但是,如果我想解析 json 文件并将其显示在 index.html 中...
它返回此错误:
Uncaught TypeError: require(...).readFileSync is not a function
这是我的代码 http://pastebin.com/n0BJfZG9我的 gulpfile 和 app.js
我错过了什么吗?为什么我不能使用普通的 Node 模块来做这种事情?
最佳答案
您应该能够直接在 Node 中请求 JSON 文件:
var myJson = require('./path/to/file.json');
// log to confirm output
console.log(JSON.stringify(myJson));
这假设 file.json
是原始 JSON,大致如下:
{
"property": "value",
"property2": "value2"
}
关于javascript - 使用node和gulp解析json文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35000286/