我必须做一个gulp任务,我试图读取一个json文件(对象数组),我想将一个对象写入另一个文件。
JSON:
{
"Files": [{
"dev": {
"POIBasePath": "poi",
"basePathSearch": "search-v1",
"contentType": "application/json",
"timeOut": 10000
}
}, {
"qa": {
"POIBasePath": "poi",
"basePathSearch": "search-v1",
"contentType": "application/json",
"timeOut": 10000
}
}]
}
Gulp任务:
gulp.task('readFile', function() {
return gulp.src('app/dataConfig.json')
.pipe(fs.readFile("app/dataConfig.json", "utf-8", function(err, data){
console.log(data);//getting the total json object here
fs.writeFile('app/scripts/apiConfig.js', data.Files[0].dev);
}))
.pipe(gulp.dest('./dest/'))
})
这时当我试图访问data.Files [0] .dev我得到undefined
任何帮助将不胜感激