[英]C# - How do I deserialize json from Azure DevOps Work Item List?
从 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”?
您可以创建模型如下:
public class FieldsModel
{
[JsonProperty("System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty("System.Title")]
public string SystemTitle { get; set; }
}
public class WorkItemModel
{
public int id { get; set; }
public int rev { get; set; }
public FieldsModel fields { get; set; }
}
public class Root
{
public int count { get; set; }
public List<WorkItemModel> value { get; set; }
}
//using as below
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.