Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

json - 具有OData的PowerShell ConvertFrom-Json返回空集合(PowerShell ConvertFrom-Json with OData returns empty collection)

I have faced with strange issue in time of conversion of json to the objects array

(我在将json转换为objects数组时遇到了一个奇怪的问题)

$response = Invoke-WebRequest -Method Get -UseDefaultCredentials -Uri $url;

($ response =调用WebRequest-方法Get -UseDefaultCredentials -Uri $ url;)

$result = ConvertFrom-Json -InputObject $response

($结果= ConvertFrom-Json -InputObject $响应)

It returns empty collection (value=System.Object[]) despite the json is full of content.

(尽管json充满了内容,它仍返回空集合(value = System.Object [])。)

Could you please advise possible cause and solution of this issue.

(您能否建议此问题的可能原因和解决方案。)

PS.

(PS。)

It works fine when url contains specific Key and has issue only for the GetAll case.

(当url包含特定的Key且仅在GetAll情况下有问题时,它可以正常工作。)

  ask by Andreas Petrov translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Usually -inputobject can only process 1 item.

(通常,-inputobject只能处理1个项目。)

It's more of a placeholder for piping.

(它更像是管道的占位符。)

If $response is an array, you'll have to do it this way, so convertfrom-json's process block can process all the items.

(如果$ response是一个数组,则必须采用这种方式,因此convertfrom-json的process块可以处理所有项目。)

$result = $response | ConvertFrom-Json

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...