【发布时间】:2021-09-24 16:09:06
【问题描述】:
致力于从 Azure Devops 中提取工作项:
根据这篇文章,响应如下:https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/list?view=azure-devops-rest-6.0
{
"count": 2,
"value": [
{
"id": 297,
"rev": 1,
"fields": {
"System.AreaPath": "Fabrikam-Fiber-Git",
"System.Title": "Customer can sign in using their Microsoft Account",
...
}
},
{
"id": 298,
"rev": 1,
"fields": {
"System.AreaPath": "Fabrikam-Fiber-Git",
"System.Title": "Customer can log out",
...
}
}
]
}
我假设它的对象看起来像这样:
public class WorkItemModel
{
public int id { get; set; }
public int rev { get; set; }
public FieldsModel fields { get; set; }
}
public class FieldsModel
{
public string AreaPath { get; set; }
public string Title { get; set; }
}
但是如何将其反序列化为正确的对象?而“System.AreaPath”和“System.Title”又是如何处理的?
【问题讨论】:
-
在
Newtonsoft.Json中,您可以将JsonProperty属性添加到属性,使其看起来像public class FieldsModel { [JsonProperty("System.AreaPath")] public string AreaPath {get; set;} ... -
看起来有可用的包,其中包含您需要的模型:azure-devops
标签: c# api serialization azure-devops tfs-workitem