简体   繁体   English

Powershell:无法解析从 Invoke-RestMethod 返回的 json

[英]Powershell: Unable to parse json returned from Invoke-RestMethod

I try to parse a json string returned from an API call.我尝试解析从 API 调用返回的 json 字符串。

$Response = Invoke-RestMethod -Uri $URIValue -Method Post -Headers $Headers -Body $requestBody -ContentType 'application/json; charset=utf-8'

$Response #Returns: {"results":[{"tables":[{"rows":[{"[Quantity]":200}]}]}]}

Now that I try to parse it Response | ConvertFrom-Json现在我尝试解析它Response | ConvertFrom-Json Response | ConvertFrom-Json I get the following error: ConvertFrom-Json: Conversion from JSON failed with error: Unexpected character encountered while parsing value: . Path '', line 0, position 0. Response | ConvertFrom-Json我收到以下错误: ConvertFrom-Json: Conversion from JSON failed with error: Unexpected character encountered while parsing value: . Path '', line 0, position 0. ConvertFrom-Json: Conversion from JSON failed with error: Unexpected character encountered while parsing value: . Path '', line 0, position 0.

What am I doing wrong?我究竟做错了什么?

The actual solution:实际解决方案:

$Response.Substring(1) | $Response.Substring(1) | ConvertFrom-Json ConvertFrom-Json 格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM