2017-02-16 61 views
0

我现在有一个非常奇怪的问题。Grunt - 无法在PowerShell之后读取Json文件ConvertTo-Json

我正在创建我的grunt-cache-breaker使用的文件列表。我生成使用此PowerShell脚本文件的列表:

$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path 

$file = @{} 

#GET HTML FILES 
$Dir = get-childitem $ScriptDir\Helix -recurse 
$file = $Dir | where {$_.extension -eq ".html" } | % {$_.FullName} 
#END 

$file | convertto-jSon | out-file $ScriptDir\htmlfiles.json 

这就产生了一个文件,包含像这样

[ 
    "C:\\test\test1.html", 
    "C:\\test\test1.html", 
    "C:\\test\test1.html" 
] 

我缓存断路器代码:

module.exports = function(grunt) { 
grunt.initConfig({ 
    listOfHtmlPaths: grunt.file.readJSON('htmlfiles.json'), 
    cachebreaker: { 
     dev: { 
      options: { 
       match: ['.js', '.css', 'min.css'], 
       src: 
       { path: 'Helix/**/*' } 
      }, 
     files: 
      { src: ['<%= listOfHtmlPaths %>'], } 
     }, 
    }, 
}); 
grunt.loadNpmTasks('grunt-cache-breaker'); 
grunt.registerTask('default', ['cachebreaker']); 
}; 

我跑后PowerShell然后运行Grunt,但我得到以下错误:

错误:Unab解析“bustAFile.json”文件(Unexpected token?)。

如果我将bustAFile.json的全部内容复制到新的记事本文件中,则完全不需要保存它。有用。

是Poweshell添加一些奇怪的编码,我看不到?

回答

0

迫使ASCII编码的PowerShell来输出固定我的问题

$file | convertto-jSon -Compress | out-file $ScriptDir\bustAFile.json -encoding ascii 

看来,JSON解析时咕噜无法读取其他编码。