2

下面是我需要传递给 API 的键值对。不知道我哪里错了

$Body = @{
    
    hostName            = 'null'
    hostOperatingSystem = 0
    optionalFilter1     = 'null'
    optionalFilter2     = 'null'
    description         = 'null'
    serviceName         = "ServiceManager.Logging"
    sectionName         = "Services"
    signature           = 'null'
    value               = @( @{
            Services = @( @{
                              
                    FullPath      = "..\Service\MicroService.exe"
                    InstanceCount = 2
                })
                            
                          
        })
} | ConvertTo-Json -Depth 4


  $Response = Invoke-RestMethod -Uri $URI -Method PUT -Headers $Headers -Body $Body -ContentType 'application/json'

下面是我得到的错误

Invoke-RestMethod : {"":["JsonToken EndArray is not valid for closing JsonType Object. Path '', line 14, position 15."],"value":["Unexpected character encountered while parsing value: [. Path 'value', line 5, position 15."]}
4

1 回答 1

0
$Body = @{
    
    hostName            = '';
    hostOperatingSystem = 0;
    optionalFilter1     = '';
    optionalFilter2     = '';
    description         = '';
    serviceName         = "ServiceManager.Logging";
    sectionName         = "Services";
    signature           = 'null';
    value               = '{"Services": [{"Fullpath":"..\\MicroService.exe","InstanceCount": 2}]}'

} | ConvertTo-Json -Depth 10

这是正确的格式

于 2020-10-15T19:49:54.283 回答