使用ConvertTo-Json转换为JSON时保留数据类型名称 [英] Preserve datatype name when converting to JSON with ConvertTo-Json

查看:600
本文介绍了使用ConvertTo-Json转换为JSON时保留数据类型名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的SSIS目录环境导出到JSON文件(使用PowerShell).当我选择正确的列我看到字符串"和的Int16"作为类型值: 但是当我使用 ConvertTo转换为JSON时-Json 它显示int值而不是字符串值: 有什么建议吗?

I'm trying to export my SSIS catalog environment to a JSON file (with PowerShell). When I select the right columns I see "String" and "Int16" as value for the Type: but when I convert to JSON with ConvertTo-Json it shows the int values instead of the string values: Any suggestions?

推荐答案

看起来Type的值是[System.Data.DbType]类型. ConvertTo-Json将值名称转换为DbType枚举的基础数值.

Looks like the Type values are of type [System.Data.DbType]. ConvertTo-Json converts the value names to the underlying numerical value of the DbType enum.

您可以使用Select-Object语句覆盖此行为:

You can override this behavior with the Select-Object statement:

$Environment.Variables |Select-Object Name,Description,@{Name='Type';Expression={"$($_.Type)"}},Sensitivity,Value |ConvertTo-Json

这篇关于使用ConvertTo-Json转换为JSON时保留数据类型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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