Deserialize JSON subdocument

后端 未结 1 471
长发绾君心
长发绾君心 2021-01-25 02:16

I\'m calling the JIRA Rest API to recieve a list of Worklog Objects.

The JSON I recieve looks like.

{
\"startAt\": 0,
\"maxResults\": 1,
\"total\": 1,
\         


        
1条回答
  •  滥情空心
    2021-01-25 02:29

    Either create a "RootObject" class that does contain the properties:

    public class RootObject 
    {
        public int startAt { get; set; }
        public int maxResults { get; set; }
        public int total { get; set; }
        public List worklogs { get; set; }
    }
    

    And deserialize into that:

    var rootObject = JsonConvert.DeserializeObject(json);
    // access rootObject.worklogs
    

    Or step into the parsed JSON and deserialize from there:

    JObject o = JObject.Parse(json);
    JToken worklogsJson = o.SelectToken("worklogs");
    var worklogs = worklogsJson.ToObject>();
    

    0 讨论(0)
提交回复
热议问题