【发布时间】:2015-06-01 02:54:07
【问题描述】:
我正在编写一个脚本来更改 JSON 文件,但是当文件转换回 JSON 时,它会扩展特殊字符。
例如,JSON 文件包含带有“&”的密码。复制问题的一种快速方法是使用以下命令:
PS> "密码&123" |转换为 JSON 输出为:“密码\u0026123”
##Here is how I import the JSON FILE:
$jsonfile = (Get-Content .\example.json -Encoding Ascii) -join "`n" | ConvertFrom-Json
##Exporting JSON FILE without modifying it.
$jsonfile | ConvertTo-Json |Out-File "new.json"
--这里是一个简化的 JSON FILE 示例
{
"Server1":
{
"username":"root",
"password":"Password&dfdf"
},
"Server2":
{
"username":"admin",
"password":"Password&1234"
}
}
【问题讨论】:
标签: json powershell