powershell - 在 Powershell 中检索 system.object 基本类型的字符串值
问题描述
我有来自 http post 请求的结果,我将内容存储在一个变量中。
$response = Invoke-WebRequest -Uri "https://xxxxxx" -Method Post -Body $Body -Headers $header
$Content =$response.Content
内容如下所示:
{"id":"246584121546545124545"}
现在我只想要 id 的值。我尝试使用选择对象和属性参数来获取 id 的值。但它不起作用,因为内容是一个字符串。看起来很简单,但找不到检索值的方法。
PS C:\Scripts> $Content.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
解决方案
尝试从 JSON 解析为自定义 PS 对象,然后访问该id
属性:
> $x = ConvertFrom-Json -InputObject $Content
> $x.id
推荐阅读
- c++ - 如何将任何化合物还原为非化合物类型
- elasticsearch - Hibernate Search Mass Indexer 不会删除映射
- vba - 在VBA中将整数变量转换为带有前导零的字符串
- sql - 最大日期的条件左连接和第二个表中的 where 子句
- load-balancing - HaProxy - 根据查询字符串直接到后端服务器
- c# - 将 Xamarin 连接到 Python MySQL 连接器
- fscheck - FsCheck:生成 ArrayList 的任意元素,其元素为 C# 中的任意元素
- sql-server - 备份用于 SQL Server 数据库的 SAN
- html - Angular 6:使事件在 *ngFor-dynamically-generated-template-elements 上同样动态
- javascript - jQuery 问题无法检索或设置属性,“未定义”