简体   繁体   中英

How to read from Multi-Dimensional dictionary C#

I am trying to figure out a better way to handle this object/dictionary puzzle that I have going on here.

Basically, I am getting a JSON iResponse (rest sharp) and deserializing into a Dictionary. That works fine, but I get a massive dictionary that also contains objects and possibly more dictionarys? I am a little confused.

Here is my code that grabs the response to put into a dictionary:

var TicketInfo = jss.Deserialize<Dictionary<dynamic, dynamic>>(ticketExistsJSON.Content);

This is what I am getting in console:

这在我的JiraTicketInfo中

So this is inside my JiraTicketInfo variable. You can see its full of key value pairs, but inside the value of those key value pairs is another dictionary? In this dictionary contains the key value pairs I want. I specifically only want number 1.

I found a way to finally get it with

Dictionary JiraTicketInfo = TicketInfo["issues"][0]["fields"];

var bumStatus = (object[])JiraTicketInfo["customfield_10004"];

var numStatusDict = (Dictionary)bumStatus[0];

JiraOrg = numStatusDict["name"].ToString();

But I feel like there is a much simpler way to obtain this, but my brain cant seem to understand the multi-dimensional dictionary

Any help would be much appreciated!

I am not even looking for an answer, just a place where to find one. Thank you :)

here is my JSON response:

{ "expand": "names,schema", "startAt": 0, "maxResults": 1, "total": 1, "issues": [ { "expand": "customfield_10087.properties,operations,versionedRepresentations,editmeta,changelog,renderedFields", "id": "18293", "self": "https://www.myjirahost.com/rest/api/2/issue/18293", "key": "SS-2991", "fields": { "customfield_10070": null, "customfield_10071": null, "customfield_10072": null, "customfield_10073": null, "customfield_10074": null, "customfield_10075": null, "customfield_10089": null, "customfield_10004": [ { "id": "99", "name": "Organization Name B", "_links": { "self": "https://www.myjirahost.com/rest/servicedeskapi/organization/99" } } ], "environment": null, "duedate": null } } ] }

Solved with help from you all using resttosharp website and building out classes:

RootObject JiraIssueObj = JsonConvert.DeserializeObject(ticketExistsJSON.Content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM