Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取转换为Json以返回所需格式时出现问题_Json_Powershell - Fatal编程技术网

获取转换为Json以返回所需格式时出现问题

获取转换为Json以返回所需格式时出现问题,json,powershell,Json,Powershell,我有一个API,它希望JSON是一种格式。我似乎无法获得正确的数组括号 正如您将在预期格式中看到的,有一个括号内的[]部分用于联系人。我的代码缺少括号 如有任何建议,将不胜感激 以下是预期的格式: 这是我的代码和输出: []用于列表/数组-使用以下cmdlet将联系人=@(@{…})替换为联系人=@(@{…}):{“版本”:0,“createDate:”,“…}|从Json转换为表达式,这将显示以下特定部分:联系人=,[pscustomobject]{…(在[pscustomobject]前面使

我有一个API,它希望JSON是一种格式。我似乎无法获得正确的数组括号

正如您将在预期格式中看到的,有一个括号内的[]部分用于联系人。我的代码缺少括号

如有任何建议,将不胜感激

以下是预期的格式:

这是我的代码和输出:


[]
用于列表/数组-使用以下cmdlet将
联系人=@(@{…})
替换为
联系人=@(@{…})
{“版本”:0,“createDate:”,“…}|从Json转换为表达式
,这将显示以下特定部分:
联系人=,[pscustomobject]{…
(在
[pscustomobject]
前面使用
{        
    "version": 0,
    "createDate": "",
    "updateDate": "",
    "enabled": true,
    "name": "1157 - Company X (X57)",
    "contacts": 
    [
        { 
            "notifications": {
                "receipt": true,
                "recency": false,
                "data": false,
                "failure": true
                },
                "email": "BettrAEs@mycompany.com",
                "firstName": "CCC",
                "lastName": "AE",
                "company": "My Company"
        }
    ]
}
$jinfo = [pscustomobject]@{
    version    = 0
    createDate = ''
    updateDate = ''
    enabled    = $true
    name       = '1157 - Company X (X57)'
    contacts = @{
        notifications = [pscustomobject]@{
            receipt = $true
            recency = $false
            data    = $false
            failure = $true
        }
        email       = 'BettrAEs@mycompany.com'
        firstName   = 'CCC'
        lastName    = 'AE'
        company     = 'My Company'
    }
}|convertTo-Json
$jinfo
**ouput**
{
    "version":  0,
    "createDate":  "",
    "updateDate":  "",
    "enabled":  true,
    "name":  "1157 - Company X (X57)",
    "contacts":  {
                     "email":  "BettrAEs@mycompany.com",
                     "notifications":  {
                                      "receipt":  true,
                                      "recency":  false,
                                      "data":  false,
                                      "failure":  true
                                  },
                     "firstName":  "CCC",
                     "company":  "My Company",
                     "lastName":  "AE"
                 }
}