首页 > 解决方案 > 如何反序列化 JSON 数组?

问题描述

我正在尝试在 DevTest Lab 中向 VM 添加工件,并且我想动态传递工件名称。下面是我的参数

"Artifacts": {
      "type": "array"
},

在资源部分我称之为

"artifacts":["[parameters('Artifacts')]"]

我从 powershell 文件中调用这个 ARM 如下

$sampleJob += Start-Job -Name $fileName -FilePath $scriptlocation -ArgumentList  $artifact

$artifact 被定义为对象类型 Object[]

运行脚本时出现以下错误。

"message": "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Microsoft.DevTestLab.VirtualMachine.Data.Models.Rest.ArtifactInstallProperties' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.

如何解决上述错误。任何帮助都将不胜感激。谢谢你。

标签: azure-resource-manager

解决方案


在“资源”部分中,删除外部的一对方括号。它应该看起来像:

"artifacts": "[parameters('Artifacts')]"

推荐阅读