json - 使用 PUT 方法更新 JSON 中的值
问题描述
我有一个嵌套的 JSON 文件。我想用 PUT 方法更新一些值。我可以更改一些值,但问题在于嵌套值。
$Authorization = "Bearer API-KEY"
$update = [ordered]@{
name = 'ppp'
asset_tag = 'BBB'
custom_fields = @(
[ordered] @{
Mediensatz = @(
[ordered] @{
value = "B2T-XXX"
}
)
}
)
}
$json = $update | ConvertTo-Json -Depth 100
#Write-Host $json
$response = Invoke-RestMethod 'URL' -Method Put -Body $json -ContentType 'application/json' -Headers @{'Authorization' = $Authorization}
我的 JSON 文件如下所示:
{
"total": 888,
"rows": [
{
"id": 11,
"name": "AAA",
"asset_tag": "CCC",
"model": {
"id": 34,
"name": "TTT"
},
"user_can_checkout": true,
"custom_fields": {
"Mediensatz": {
"field": "lll",
"value": "B2T-YYY",
"field_format": "ANY"
},
"Ueberschreibschutz": {
"field": "lll",
"value": "2019-07-10",
"field_format": "DATE"
}
}
}
我可以更改“名称”和“资产标签”,但问题是custom_fields → Mediensatz → 价值中的“价值” 。
当我尝试运行我的代码时,Write-Host $json
它看起来像这样:
{
"name": "PPP",
"asset_tag": "BBB",
"custom_fields": [
{
"Mediensatz": [
{
"value": "B2T-XXX"
}
]
}
]
}
解决方案
推荐阅读
- c++ - 当模拟对象包装在 unique_ptr 中时,为什么 GoogleMock 会报告模拟对象泄漏?
- php - 如何将 sonarcloud 与 bitbucket 集成?
- javascript - 如何使用角度 6 动态显示/隐藏创建分区
- firebase - 导入 Firebase_Messaging 会导致构建失败
- javascript - SyntaxError:预期的表达式,得到''
- java - 如何转换列表的日期数据
进入 SimpleDateFormat - hyperledger-fabric - HyperLedger Fabric SDK Go 显示无法将 nil 转换为 csr.KeyRequest 类型
- php - 如何验证服务器上的访问令牌
- c++ - 如何为特定类型专门化模板类方法?
- swift - 快速获取用户国家