解析模板失败:错误解析JSON:无效字符‘圣保罗’寻找值的开头
我收到这个错误,当我使用
$Parsed_json | ConvertTo-Json -Depth 999 -Compress |
Out-File $nameOfJsonFile -Force 这是:
解析模板失败:解析JSON错误:寻找值的开头的无效字符‘JSON’
使用时
$Parsed_json | ConvertTo-Json -Depth 999 | Out-File $nameOfJsonFile -ForceJSON在线验证器批准我的JSON。
到目前为止,我对这个主题的研究是,在使用Out-File时打印自己的Unicode字符是造成这个问题的原因。我的JSON文件的编码是ASCII,任何关于这个问题的帮助都将不胜感激。
发布于 2016-05-23 10:10:25
显然这是个编码问题。解决方案是使用ASCII编码创建输出文件(实际上,它是一个ANSI编码,但由于参数参数名为Ascii,为了简单起见,让我们继续使用该参数),例如:
$Parsed_json | ConvertTo-Json -Depth 999 -Compress |
Out-File $nameOfJsonFile -Encoding Ascii -Force或者像这样(Set-Content默认使用ASCII编码):
$Parsed_json | ConvertTo-Json -Depth 999 -Compress |
Set-Content $nameOfJsonFile -Forcehttps://stackoverflow.com/questions/37294273
复制相似问题