0

I'm having a hard time understanding how to deserialize JSON responses in C#. Specifically, how to make models for them. Let's say I have a JSON response that looks like this

{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 4214,
"issues": [
    {
        "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
        "id": "1233",
        "self": "....",
        "key": "HeiSwits",
        "fields": {
            "reporter": {
                "self": "https://jira.planetabax.com/rest/api/2/user?username=nltomkoc",
                "name": "nltomkoc",
                "key": "nltomkoc",
                "emailAddress": "tom.kocken@abax.nl",
                "avatarUrls": {
                    "48x48": "https://jira.planetabax.com/secure/useravatar?avatarId=10346",
                    "24x24": "https://jira.planetabax.com/secure/useravatar?size=small&avatarId=10346",
                    "16x16": "https://jira.planetabax.com/secure/useravatar?size=xsmall&avatarId=10346",
                    "32x32": "https://jira.planetabax.com/secure/useravatar?size=medium&avatarId=10346"
                },
                "displayName": "Tom Kocken",
                "active": true,
                "timeZone": "Europe/Berlin"
            },
            "customfield_12101": null,
            "customfield_12100": null,
            "aggregateprogress": {
                "progress": 0,
                "total": 0
            },
            "votes": {
                "self": "https://jira.planetabax.com/rest/api/2/issue/ASAPSD-4298/votes",
                "votes": 0,
                "hasVoted": false
            },
            "issuetype": {
                "self": "https://jira.planetabax.com/rest/api/2/issuetype/10801",
                "id": "10801",
                "description": "Customer issue. Application Support  & Development are the only ones that can create these issues",
                "iconUrl": "https://jira.planetabax.com/secure/viewavatar?size=xsmall&avatarId=13610&avatarType=issuetype",
                "name": "Customer",
                "subtask": false,
                "avatarId": 13610
            },
            "project": {
                "self": "https://jira.planetabax.com/rest/api/2/project/12008",
                "id": "12008",
                "key": "ASAPSD",
                "name": "Application Support & Development Service Desk",
                "projectTypeKey": "service_desk",
                "avatarUrls": {
                    "48x48": "https://jira.planetabax.com/secure/projectavatar?pid=12008&avatarId=13624",
                    "24x24": "https://jira.planetabax.com/secure/projectavatar?size=small&pid=12008&avatarId=13624",
                    "16x16": "https://jira.planetabax.com/secure/projectavatar?size=xsmall&pid=12008&avatarId=13624",
                    "32x32": "https://jira.planetabax.com/secure/projectavatar?size=medium&pid=12008&avatarId=13624"
                }
            },
            "created": "2021-06-21T10:09:15.000+0200",
            "duedate": "2021-07-12"
        }
    },

how can I only get the issues[] object and create an object from that? This is what I've got so far:

    public class JiraIssues
    { 
        [JsonProperty("issues")]
        public List<JiraIssue> Issues { get; set; }
    }

    public class JiraIssueModel
    {
        public JiraIssue Issue { get; set; }
    }

I am trying to get a List by deserializing.

  • What is the error you are getting when you deserialize again `JiraIssues`. Like `JsonConvert.DeserializeObject(jsonString);`. – user1672994 Jun 21 '21 at 09:25
  • @user1672994 This is the error I am getting " Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[JiraService+JiraIssueModel] Path 'expand', line 1, position 10." It is the first 4 properties in the JSON response who is making this not work I think. –  Jun 21 '21 at 09:26
  • Could you also show us the code you are attempting to deserialize the JSON with? – phuzi Jun 21 '21 at 09:28

0 Answers0