我正在尝试使用八达通客户端(github source)调用/api/progression/<project-id>
端点来获取某个项目的发布进度,如下所示:
// _repository is of type IOctopusRepository
_repository.Client.Get<ProgressionResource>($"/api/progression/{projectId}");
立即抛出OctopusDeserializationException
说:
无法处理来自服务器的响应:无法反序列化当前 JSON对象(例如{&#34; name&#34;:&#34; value&#34;})进入类型 &#39; System.Linq.IOrderedEnumerable`1 [Octopus.Client.Model.DashboardItemResource]&#39; 因为该类型需要一个JSON数组(例如[1,2,3])来反序列化 正确。 要修复此错误,请将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型,以使其成为正常的.NET type(例如,不是像整数这样的基本类型,不是集合类型 像数组或List一样,可以从JSON对象反序列化。 JsonObjectAttribute也可以添加到类型中以强制它 从JSON对象反序列化。 Path&#39; Releases [0] .Deployments.Environments-1.Id&#39;,第55行,第15位。响应内容:{ &#34;环境&#34;:[ { &#34; Id&#34;:&#34;环境-1&#34;, &#34;名称&#34;:&#34;测试环境&#34; },
在ReleaseProgressionResource
的每个版本(Releases
类型)中,都有一个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 :(得分:0)
这是整个部署对象吗? 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"
}
}
}
}