无法将 JSON 数组反序列化为类型“Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy" [英] Cannot deserialize JSON array into type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy'

查看:13
本文介绍了无法将 JSON 数组反序列化为类型“Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模板的目的是将子网添加到现有 Vnet,但在使用 powershell 命令执行时

The aim of the template is to add subnets to an existing Vnet but when executing it using the powershell command

   New-AzureRmResourceGroupDeployment -Name testing -ResourceGroupName rgname -TemplateFile C:\Test\deploy.json -TemplateParameterFile C:\Test\parameterfile.json

显示以下错误,我真的不明白这是什么意思.这是错误*错误:代码=无效请求内容;消息=请求内容无效且无法反序列化:'无法填充 JSON数组到类型Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy".路径'properties.template.resources[0].copy'"*

The following error is displayed and I really cant understand what it means.Here is the error * "Error: Code=InvalidRequestContent; Message=The request content was invalid and could not be deserialized: 'Cannot populate JSON array ontotype'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy'. Path 'properties.template.resources[0].copy' "*

以下是我的输入文件(parameter.json)

Following is my input file(parameter.json)

    {
     "VNetSettings":{
     "value":{
        "name":"VNet2",
        "addressPrefixes":"10.0.0.0/16",
        "subnets":[
            {
                "name": "sub5",
                "addressPrefix": "10.0.5.0/24"
            },
            {
                "name":"sub6",
                "addressPrefix":"10.0.6.0/24"
            }
        ]
    }
  }
}

以下是我的模板(deploy.json)

The following is my template(deploy.json)

   {
    "contentversion":"1.0.0.0",
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "parameters":{
        "VNetSettings":
                   {"type":"object"},
        "noofsubnets":
          {
            "type":"int"
          }
    },
"resources":
[
{
    "type":"Microsoft.Network/virtualNetworks/subnets",
    "apiVersion": "2015-06-15",
    "location":"[resourceGroup().location]",
    "copy": [
      {
        "name":"subnets",
        "count":"[parameters('noofsubnets')]",
        "input": {
             "name": "[concat(parameters('VNetSettings').name, '/',parameters('VNetSettings').subnets[copyIndex('subnets')].name)]",                
             "properties":{
                 "addressPrefix": "[parameters('VNetSettings').subnets[copyIndex('subnets')].addressPrefix]"
                }
             }
          }
       ]
      }
   ]
}

我想错误应该在复制语句内部和周围.

I guess the error should be in and around the copy statement.

推荐答案

这是解决方案.感谢 @4c74356b41 提供线索.

Here is the solution.Thanks to @4c74356b41 for your leads.

    {
     "contentversion":"1.0.0.0",
     "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
     "parameters":{
        "VNetSettings":{"type":"object"},
        "noofsubnets":
          {
            "type":"int"
          }
       },
     "variables":
      {
        "vnetname":"[parameters('VNetSettings').name]"
      },
    "resources":
    [
    {
    "type":"Microsoft.Network/virtualNetworks/subnets",
    "name": "[concat(variables('vnetname'), '/',parameters('VNetSettings').subnets[copyIndex()].name)]",
    "apiVersion": "2015-06-15",
    "location":"[resourceGroup().location]",
    "properties":{
       "addressPrefix": "[parameters('VNetSettings').subnets[copyIndex()].addressPrefix]"
      },
    "copy":{
        "name":"subnetcopy",
        "count":"[parameters('noofsubnets')]"
        }
     }
  ]
}

这篇关于无法将 JSON 数组反序列化为类型“Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.TemplateResourceCopy"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆