C# Naviagate Object inside List

SSinhg 316 Reputation points
2021-05-19T15:29:44.1+00:00

Hi,

This is the JSON response I'm getting from Jira API 3 URL

How do I Navigate and populate schema?

// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 
    public class Schema
    {
        public string type { get; set; }
        public string custom { get; set; }
        public int customId { get; set; }
        public string system { get; set; }
        public string items { get; set; }
    }

public class Root
{
    public string id { get; set; }
    public string key { get; set; }
    public string name { get; set; }
    public bool custom { get; set; }
    public bool orderable { get; set; }
    public bool navigable { get; set; }
    public bool searchable { get; set; }
    public List<string> clauseNames { get; set; }
    public string untranslatedName { get; set; }
    public Schema schema { get; set; }
}

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-fields/#api-rest-api-3-field-search-get

[
  {
    "id": "description",
    "name": "Description",
    "custom": false,
    "orderable": true,
    "navigable": true,
    "searchable": true,
    "clauseNames": [
      "description"
    ],
    "schema": {
      "type": "string",
      "system": "description"
    }
  },
  {
    "id": "summary",
    "key": "summary",
    "name": "Summary",
    "custom": false,
    "orderable": true,
    "navigable": true,
    "searchable": true,
    "clauseNames": [
      "summary"
    ],
    "schema": {
      "type": "string",
      "system": "summary"
    }
  }
]
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,656 Reputation points
    2021-05-20T07:41:46.243+00:00

    Hi SwatantraSingh-2674,
    You can add to a list and then access them.

    List<Schema> schemas = new List<Schema>();  
                 
    Root[] data = JsonConvert.DeserializeObject<Root[]>(responseString);  
     foreach (var x in data)  
    {  
              roots.Add(x.schema);  
    }  
         
      
    foreach (var x in schemas)  
    {  
           Console.WriteLine(x.type+x.system);  
      
    }  
    

    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Artemiy Moroz 271 Reputation points
    2021-05-19T16:13:04.31+00:00

    hi there! You see that you actually have the array of Roots. So I would suggest trying to do:
    Root[] myDeserializedClass = JsonConvert.DeserializeObject<Root[]>(myJsonResponse);

    Artem


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.