2016-09-23 58 views
0

我想获得释放级数使用八达通客户端(github source)调用/api/progression/<project-id>端点这样一个特定的项目:八达通客户端无法解析部署字典中ReleaseProgressionResource

// _repository is of type IOctopusRepository 
_repository.Client.Get<ProgressionResource>($"/api/progression/{projectId}"); 

这是立即抛出OctopusDeserializationException说:

无法处理从服务器响应:不能反序列化当前 JSON对象(例如{“名称”:“值”})到 类型“System.Linq.IOrderedEnu merable`1 [Octopus.Client.Model.DashboardItemResource]' ,因为该类型需要JSON数组(例如, [1,2,3])正确地反序列化 。 要解决此错误,请将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型,以便它是一个正常的.NET类型(例如,不是像integer这样的基本类型,也不是集合键入 就像数组或列表),可以从JSON对象反序列化。 也可以将JsonObjectAttribute添加到该类型中,以强制它从一个JSON对象反序列化为 。 Path'Releases [0] .Deployments.Environments-1.Id',line 55,position 15 .. Response content:{ “Environments”:[ {Id}:“Environments-1”, “Name “:‘从Releases测试环境’ },

在各推出(ReleaseProgressionResource类型)有一个Deployments丙是Dictionary<string,IOrderedEnumerable<DashboardItemResource>>类型。但是,似乎客户端(已经被使用这个API)不能序列化。从异常消息看来,客户端似乎试图将其解析为JSON数组。

这里的原始JSON端点响应的样品Deployments部分(有一些虚拟数据):

"Deployments": { 
     "Environments-1": { 
      "Id": "Deployments-12345", 
      "ProjectId": "Projects-123", 
      "EnvironmentId": "Environments-1", 
      "ReleaseId": "Releases-12345", 
      "DeploymentId": "Deployments-12345", 
      "TaskId": "ServerTasks-12345", 
      "ReleaseVersion": "5.4.3", 
      "Created": "2016-09-22T21:26:38.886+00:00", 
      "QueueTime": "2016-09-22T21:26:38.855+00:00", 
      "CompletedTime": "2016-09-22T21:29:48.355+00:00", 
      "State": "Success", 
      "HasPendingInterruptions": false, 
      "HasWarningsOrErrors": false, 
      "ErrorMessage": "", 
      "Duration": "3 minutes", 
      "IsCurrent": true, 
      "IsPrevious": false, 
      "IsCompleted": true, 
      "Links": { 
      "Self": "/api/deployments/Deployments-12345", 
      "Release": "/api/releases/Releases-12345", 
      "Task": "/api/tasks/ServerTasks-12345" 
      } 
     } 
} 

没有人有任何想法什么可能发生的/我可能是做错了什么? 在此先感谢。

回答

0

是整个Deployment对象吗? JSON对象需要用括号括起来。

{ 
    "Deployments": { 
     "Environments-1": { 
      "Id": "Deployments-12345", 
      "ProjectId": "Projects-123", 
      "EnvironmentId": "Environments-1", 
      "ReleaseId": "Releases-12345", 
      "DeploymentId": "Deployments-12345", 
      "TaskId": "ServerTasks-12345", 
      "ReleaseVersion": "5.4.3", 
      "Created": "2016-09-22T21:26:38.886+00:00", 
      "QueueTime": "2016-09-22T21:26:38.855+00:00", 
      "CompletedTime": "2016-09-22T21:29:48.355+00:00", 
      "State": "Success", 
      "HasPendingInterruptions": false, 
      "HasWarningsOrErrors": false, 
      "ErrorMessage": "", 
      "Duration": "3 minutes", 
      "IsCurrent": true, 
      "IsPrevious": false, 
      "IsCompleted": true, 
      "Links": { 
       "Self": "/api/deployments/Deployments-12345", 
       "Release": "/api/releases/Releases-12345", 
       "Task": "/api/tasks/ServerTasks-12345" 
      } 
     } 
    } 
} 
+0

没有这只是它未能序列化的部分。这是一个更大结构的一部分。我获取'ProgressionResource',其中包含'ReleaseProgressionResources'集合,其中包含此部署失败的'Deployments'字典,因为反序列化器试图将其解析为名为'Environments-1'属性的对象作为一个字典。 – valorl

相关问题