我創建一個JSON格式的字符串構建JSON字符串時\輸出是正確的,只是所有qoutes已被替換的\字符,而不是」「正在改變在PowerShell中
{
\$schema\: \https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#\,
\contentVersion\: \1.0.0.0\,
\parameters\: {
\type\: \web\,
\name\: \Cluster\,
\hockeyAppToken\: \\,
\hockeyAppId\: \\,
\regionId\: \southcentralus\,
\requestSource\: \IbizaAIExtension\
}
}
代碼生成Json
$fullDoc = '
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": ' + $armsettings + '}'
$json = $fullDoc | ConvertTo-Json -depth 100
$json = $json.Replace("\r","")
$json = $json.Replace("\n",([Environment]::NewLine))
$json = $json.Replace("@{","{")
$json = $json.Trim()
$json = $json.Replace($json.Substring(0,1),"")
Write-Host $json
有關如何解決此問題的任何想法?
這是正確格式的文檔
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"type": {
"value": "web"
},
"name": {
"value": "Cluster"
},
"hockeyAppToken": {
"value": ""
},
"hockeyAppId": {
"value": ""
},
"regionId": {
"value": "southcentralus"
},
"requestSource": {
"value": "IbizaAIExtension"
}
}
}
爲什麼不'$ fullDoc | ConvertTo-Json | ConvertFrom-Json'? – Avshalom
這到底是怎麼回事? @Avshalom – 4c74356b41
@Avshalom。謝謝!這就像一個魅力:) –