使用以反斜杠结尾的字符串时,ConvertTo-Json 会抛出错误 [英] ConvertTo-Json throws error when using a string terminating in backslash

查看:41
本文介绍了使用以反斜杠结尾的字符串时,ConvertTo-Json 会抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码产生错误

W:\surge\ogre> @{SolutionDir='W:\Surge\ogre\'} | ConvertTo-Json
ConvertTo-Json : The converted JSON string is in bad format.
At line:1 char:35
+ @{SolutionDir='W:\Surge\ogre\'} | ConvertTo-Json
+                                   ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Collections.Hashtable:PSObject) [ConvertTo-Json], InvalidOperationException
    + FullyQualifiedErrorId : JsonStringInBadFormat,Microsoft.PowerShell.Commands.ConvertToJsonCommand

为什么?我怎么能解决这个问题?这是在预构建事件中,所以我试图保持单行和尽可能紧凑.

Why? How could I fix this? This is in a prebuild event so I'm trying to keep it single-line and as compact as possible.

推荐答案

使用 -Compress 开关应该可以解决您的问题.我相信这是 PowerShell 中的一个错误.其他人也有与前类似的问题.values 包含双引号

Using the -Compress switch should solve your problem. I believe this is a bug in PowerShell. Others have had similar problem with ex. values containing double quotes

这篇关于使用以反斜杠结尾的字符串时,ConvertTo-Json 会抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆