我正在尝试将以下JSON解析为PSCustomObject
[
{
"tags": [
{
"tagName": "Microsoft Teams"
},
{
"tagName": "Worldwide (Standard Multi-Tenant)"
},
{
"tagName": "General Availability"
},
{
"tagName": "Web"
},
{
"tagName": "Desktop"
}
],
"tagsContainer": {
"products": [
{
"tagName": "Microsoft Teams"
}
],
"cloudInstances": [
{
"tagName": "Worldwide (Standard Multi-Tenant)"
}
],
"releasePhase": [
{
"tagName": "General Availability"
}
],
"platforms": [
{
"tagName": "Web"
},
{
"tagName": "Desktop"
}
]
},
"id": 51230,
"title": "Microsoft Teams: New file sharing experience",
"description": "Streamline sharing with Microsoft Teams. You can now create a shareable link for any file stored in Teams and directly set the appropriate permissions. Additionally, you can also set permissions for files stored in SharePoint or OneDrive while composing a private chat or starting a channel conversation.",
"status": "Launched",
"moreInfoLink": "https://techcommunity.microsoft.com/t5/microsoft-sharepoint-blog/rich-new-file-and-sharing-experiences-throughout-microsoft-365/ba-p/960129",
"publicRoadmapStatus": "Include this month",
"created": "2019-05-08T07:00:00",
"modified": "2022-01-13T00:05:19.663",
"publicDisclosureAvailabilityDate": "March CY2021",
"publicPreviewDate": ""
}
]我将该JSON存储在这样的变量中:
$RoadmapContent = Get-Content -Raw -Path ".\M365Roadmap_single.json" | ConvertFrom-Json 这就是我的PSCustomObject:
$RoadmapItems =[PSCustomObject]@{
Title = $($RoadmapContent.title)
Tags = $($RoadmapContent.tags)
}我想把这个标签放在一个列中,比如:微软团队、全球(标准多租户)、通用可用性、Web、桌面
我曾试图这样做(但没有成功):
$RoadmapContent.Tags -join ";"我如何解析这个?
非常感谢!
编辑:
我可以访问这样的标签:
foreach ($tag in $RoadmapContent.tags) {Write-Host $Tag.tagName}但不知道如何在PSCustomObject中使用它。
发布于 2022-07-06 20:34:52
多亏了原问题中的一条评论,我们才弄明白了这一点,下面是完整的代码:
$RoadmapContent = Get-Content -Raw -Path ".\M365Roadmap_single.json" | ConvertFrom-Json
$RoadmapItems =[PSCustomObject]@{
Title = $($RoadmapContent.title)
Tags = $($RoadmapContent.tags.tagname -join ', ')
}
$RoadmapItemshttps://stackoverflow.com/questions/72889436
复制相似问题