简体   繁体   English

如何从多维词典C#读取

[英]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. 基本上,我会得到一个JSON iResponse(非常清晰)并反序列化为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. 所以这在我的JiraTicketInfo变量中。 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. 我特别只想要数字1。

I found a way to finally get it with 我找到了一种方法

Dictionary JiraTicketInfo = TicketInfo["issues"][0]["fields"]; 字典JiraTicketInfo = TicketInfo [“ issues”] [0] [“ fields”];

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

var numStatusDict = (Dictionary)bumStatus[0]; var numStatusDict =(Dictionary)bumStatus [0];

JiraOrg = numStatusDict["name"].ToString(); 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: 这是我的JSON响应:

{ "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: 在所有人的帮助下使用resttosharp网站解决了问题并建立了课程:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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