Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
已编辑的JSON正在使用PowerShell以奇怪的空格保存_Json_Powershell - Fatal编程技术网

已编辑的JSON正在使用PowerShell以奇怪的空格保存

已编辑的JSON正在使用PowerShell以奇怪的空格保存,json,powershell,Json,Powershell,所以我有一个PowerShell脚本,它需要编辑和保存配置文件的JSON代码 我使用以下方法加载它们(目前有三个): 然后,在脚本执行期间,在数组$cliConfog中操作它们的属性。然后在脚本末尾使用 $cliConfig | ConvertTo-Json -depth | Out-File $clientConfig 你可能会认为这样做可以节省开支,但不是像这样节省开支 { "serverConfigVersion": 0, "dateUpda

所以我有一个PowerShell脚本,它需要编辑和保存配置文件的JSON代码

我使用以下方法加载它们(目前有三个):

然后,在脚本执行期间,在数组
$cliConfog
中操作它们的属性。然后在脚本末尾使用

$cliConfig | ConvertTo-Json -depth | Out-File $clientConfig
你可能会认为这样做可以节省开支,但不是像这样节省开支

{
    "serverConfigVersion": 0,
    "dateUpdated": "01/01/2000",
    "errorStatus": false,
    "localClientVersion": 1.0,
    "ReleaseMain": [1.0, "01/01/2000", null],
    "BetaMain": [1.0, "01/01/2000", null],
    "ReleaseVersion": 1.0,
    "users": ["notLiam.Doyle", "Person2.Person", "Person3.Person"]
}
它像这样保存;
-出于某种原因,它甚至不让我把它粘贴进去。我认为这是一个编码问题,但我不确定在哪里。有什么想法吗?

我假设命令行更像这样,没有-depth参数,没有值,并且-append添加到out文件中:

$cliConfig | ConvertTo-Json | Out-File -Append $clientConfig
这些空格可能是混合utf16和utf8编码产生的空。不要在没有文件的情况下追加(与>>相同),或者改用设置内容或添加内容

$cliConfig | ConvertTo-Json | Out-File -Append $clientConfig