ste*_*ven 5 powershell json powershell-3.0
我目前正在从PowerShell脚本生成一个JSON文件,但它输出的是Unicode而不是特殊字符,例如'<'我在LinkText中需要HTML,但不知道如何更改编码.
这是我得到的输出:
[
{
"Id": "187303",
"LinkText": "\u003cb style =color:#d11717;\u0027\u003eAnnual General Meeting (MEET)"
},
{
"Id": "187305",
"LinkText": "\u003cb style =color:#d11717;\u0027\u003eAnnual General Meeting (MEET)"
}
]
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
$(foreach ($row in $DataSet.Tables[0].Rows){
$stockShortName = $row[0].ToString().Trim()
$id = $row[0].ToString().Trim()
$linkText = "<b style =color:`#d11717;'>$event_description"
(New-Object PSObject |
Add-Member -PassThru NoteProperty Id $id |
Add-Member -PassThru NoteProperty LinkText $linkText
)
}) | ConvertTo-JSON | Out-File $OutputFile -Encoding "default"
Run Code Online (Sandbox Code Playgroud)
我没有看到内置参数来阻止这种转换的发生。这是转换回 unicode 字符的解决方法:
[regex]::replace($json,'\\u[a-fA-F0-9]{4}',{[char]::ConvertFromUtf32(($args[0].Value -replace '\\u','0x'))})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2577 次 |
| 最近记录: |