首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >中的列表

中的列表
EN

Stack Overflow用户
提问于 2022-07-06 20:21:18
回答 1查看 24关注 0票数 0

我正在尝试将以下JSON解析为PSCustomObject

代码语言:javascript
复制
[
  {
    "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存储在这样的变量中:

代码语言:javascript
复制
$RoadmapContent = Get-Content -Raw -Path ".\M365Roadmap_single.json" | ConvertFrom-Json 

这就是我的PSCustomObject:

代码语言:javascript
复制
$RoadmapItems =[PSCustomObject]@{
        Title = $($RoadmapContent.title)
        Tags = $($RoadmapContent.tags)
}

我想把这个标签放在一个列中,比如:微软团队、全球(标准多租户)、通用可用性、Web、桌面

我曾试图这样做(但没有成功):

代码语言:javascript
复制
$RoadmapContent.Tags -join ";"

我如何解析这个?

非常感谢!

编辑:

我可以访问这样的标签:

代码语言:javascript
复制
foreach ($tag in $RoadmapContent.tags) {Write-Host $Tag.tagName}

但不知道如何在PSCustomObject中使用它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-06 20:34:52

多亏了原问题中的一条评论,我们才弄明白了这一点,下面是完整的代码:

代码语言:javascript
复制
$RoadmapContent = Get-Content -Raw -Path ".\M365Roadmap_single.json" | ConvertFrom-Json 

$RoadmapItems =[PSCustomObject]@{
        Title = $($RoadmapContent.title)
        Tags = $($RoadmapContent.tags.tagname -join ', ')
}

$RoadmapItems
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72889436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档