You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法向PropertiesCollection添加System.Int32类型的问题排查

问题分析与解决方案

问题1:布尔属性被自动转为字符串

你手动拼接的JSON中,true是布尔值,但PowerShell的Here-String处理或HTTP请求头配置问题,导致后端将其默认解析为字符串;同时Azure DevOps API在接收未指定类型的属性时,会自动按字符串类型存储。

问题2:手动指定类型后返回properties: null

你的第二个请求体存在JSON语法错误:'$type'使用了单引号,而JSON规范要求所有键必须用双引号包裹。这个错误导致API无法正确解析properties字段,最终返回null。

正确的实现方式

方式1:修正语法,正确指定布尔类型属性

如果需要布尔类型的ComposerDenyStatus,请求体需修正引号格式,并使用正确的类型标识System.Boolean:

$body = @"
{
 "comments": [
    {
      "parentCommentId": 0,
      "content": "$content",
      "commentType": 1
    }
  ],
  "properties": {
    "ComposerDenyStatus": {
      "$type": "System.Boolean",
      "$value": true
    }
  },
  "status": $status 
}
"@

方式2:用PowerShell对象转JSON避免手动拼接错误

手动拼接JSON极易出现格式问题,推荐通过PowerShell对象自动生成正确的JSON结构:

$bodyObject = [PSCustomObject]@{
    comments = @(
        [PSCustomObject]@{
            parentCommentId = 0
            content = $content
            commentType = 1
        }
    )
    properties = [PSCustomObject]@{
        ComposerDenyStatus = [PSCustomObject]@{
            '$type' = 'System.Boolean'
            '$value' = $true
        }
    }
    status = $status
}

$body = $bodyObject | ConvertTo-Json -Depth 3

额外注意事项

  • 确保请求的Content-Type头设置为application/json,否则API可能无法正确解析请求体。
  • 若需整数类型,将$type改为System.Int32,$value设为无引号的数字(如"$value": 1)。

内容的提问来源于stack exchange,提问作者Graham Reynolds

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 06:05:20