如何从 Invoke-webrequest 内容结果中向下钻取数据?
How to drilldown data from Invoke-webrequest content result?
我设法return invoke-webrequest 的内容以字符串的形式,但现在我不知道访问里面的单个值,因为它是字符串值。
这是 returned 字符串的片段,我省略了部分值
{
"odata.metadata":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description","odata.count":"18
80","value":[
{
"ActivityInstanceDestinationID":"20","ActivityName":"Task","ActivityInstan
ceID":"18","ProcessInstanceID":"1223","Destination":"a2\","StartDate
":"2021-05-10T18:47:01","FinishDate":"1900-01-01T00:00:00","Status":"Active","Du
ration":"0","ProcessName":"ReviewSub","ProcessFolder":"Work","Fol
io":"","ExpectedDuration":"0","ActivityID":"","Final_Acti
on":null,"ActivityDisplayName":"Task"
}
],"odata.nextLink":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description?$filter=StartDate%20ge%20d
atetime'2021-05-10T13:40:08'&$skip=1000"
}
我已经尝试将其转换为 json 但它将所有内容都转换为 odata.metadata 中的单个值。我想要的只是能够像数组一样访问它,例如 $var.odata.count 将输出 1880.
$Json = @'
{
"odata.metadata":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description","odata.count":"18
80","value":[
{
"ActivityInstanceDestinationID":"20","ActivityName":"Task","ActivityInstan
ceID":"18","ProcessInstanceID":"1223","Destination":"a2\","StartDate
":"2021-05-10T18:47:01","FinishDate":"1900-01-01T00:00:00","Status":"Active","Du
ration":"0","ProcessName":"ReviewSub","ProcessFolder":"Work","Fol
io":"","ExpectedDuration":"0","ActivityID":"","Final_Acti
on":null,"ActivityDisplayName":"Task"
}
],"odata.nextLink":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description?$filter=StartDate%20ge%20d
atetime'2021-05-10T13:40:08'&$skip=1000"
}
'@
$Object = ConvertFrom-Json $Json
$Object.'odata.count'
18
80
ConvertFrom-Json
反序列化 $Json
字符串,其中 'odata.count'
包含请求的值。
请注意,在您的示例中,值 1880
被换行符分割,在不同的行上输出值 18
和 80
。
我设法return invoke-webrequest 的内容以字符串的形式,但现在我不知道访问里面的单个值,因为它是字符串值。
这是 returned 字符串的片段,我省略了部分值
{
"odata.metadata":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description","odata.count":"18
80","value":[
{
"ActivityInstanceDestinationID":"20","ActivityName":"Task","ActivityInstan
ceID":"18","ProcessInstanceID":"1223","Destination":"a2\","StartDate
":"2021-05-10T18:47:01","FinishDate":"1900-01-01T00:00:00","Status":"Active","Du
ration":"0","ProcessName":"ReviewSub","ProcessFolder":"Work","Fol
io":"","ExpectedDuration":"0","ActivityID":"","Final_Acti
on":null,"ActivityDisplayName":"Task"
}
],"odata.nextLink":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description?$filter=StartDate%20ge%20d
atetime'2021-05-10T13:40:08'&$skip=1000"
}
我已经尝试将其转换为 json 但它将所有内容都转换为 odata.metadata 中的单个值。我想要的只是能够像数组一样访问它,例如 $var.odata.count 将输出 1880.
$Json = @'
{
"odata.metadata":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description","odata.count":"18
80","value":[
{
"ActivityInstanceDestinationID":"20","ActivityName":"Task","ActivityInstan
ceID":"18","ProcessInstanceID":"1223","Destination":"a2\","StartDate
":"2021-05-10T18:47:01","FinishDate":"1900-01-01T00:00:00","Status":"Active","Du
ration":"0","ProcessName":"ReviewSub","ProcessFolder":"Work","Fol
io":"","ExpectedDuration":"0","ActivityID":"","Final_Acti
on":null,"ActivityDisplayName":"Task"
}
],"odata.nextLink":"https://wdzbomfg1.com/api/odata/v3/$metadata#report_description?$filter=StartDate%20ge%20d
atetime'2021-05-10T13:40:08'&$skip=1000"
}
'@
$Object = ConvertFrom-Json $Json
$Object.'odata.count'
18
80
ConvertFrom-Json
反序列化 $Json
字符串,其中 'odata.count'
包含请求的值。
请注意,在您的示例中,值 1880
被换行符分割,在不同的行上输出值 18
和 80
。