Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从较大的JSON字符串中检索所需字符串_C#_.net_Json_Json.net - Fatal编程技术网

C# 从较大的JSON字符串中检索所需字符串

C# 从较大的JSON字符串中检索所需字符串,c#,.net,json,json.net,C#,.net,Json,Json.net,我有方法返回的JSON字符串: public List<Issues> Getdata( string jql, List<string> fields = null, int startAt = 0, int maxResult = 500) { string data = JsonConvert.SerializeObject(request); string re

我有方法返回的JSON字符串:

public List<Issues> Getdata(
        string jql,
        List<string> fields = null,
        int startAt = 0,
        int maxResult = 500)
    {
        string data = JsonConvert.SerializeObject(request);
        string result = runQuery(JiraResource.search, data, "POST"); //returns results and working fine
        SearchResponse response = JsonConvert.DeserializeObject<SearchResponse>(result);
        return response.IssueDescriptions = GetIssues(response);;
    }
我希望上述json字符串的解析器方法能够获得这些字段值的特定值,如:

“摘要”、“状态”、“受让人”, “评论”、“说明”、“创建”、“截止日期”、“环境”、“优先级”、“项目”, “报告者”、“决议”、“发布类型”、“更新”、“投票”、“组件”

我试着一个接一个的去做。但是,这很复杂,也很费时

这就是我努力的方向。但错误:对象引用未设置为对象的实例

private List<JiraIssues> GetIssues(SearchResponse response)
{
    List<JiraIssues> returnResulttoReport = new List<JiraIssues>();
    foreach (var item in response.IssueDescriptions) //error here (not sure why IssueDescriptions is NULL but before call i'm de-serializing it)
    {
        foreach (var item1 in item.Comments)
        {

        }
    }

    return returnResulttoReport; 
}
private List GetIssues(SearchResponse)
{
List returnResulttoReport=新列表();
foreach(response.IssueDescriptions中的var item)//此处出错(不确定为什么IssueDescriptions为NULL,但在调用之前,我正在反序列化它)
{
foreach(item.Comments中的var item1)
{
}
}
返回结果报告;
}
我的返回类型是
List
。是否有任何库或示例链接来执行此操作


请注意,我已经对它进行了反序列化,现在我想从中得到一个特定的列表。另外,请注意,我给出的JSON完整字符串与实际的JSON字符串不同。但它类似。请引导。

您可以这样尝试:

    public class Issuetype
    {
        public string self { get; set; }
        public string id { get; set; }
        public string description { get; set; }
        public string iconUrl { get; set; }
        public string name { get; set; }
        public bool subtask { get; set; }
    }

    public class AvatarUrls
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Project
    {
        public string self { get; set; }
        public string id { get; set; }
        public string key { get; set; }
        public string name { get; set; }
        public AvatarUrls avatarUrls { get; set; }
    }

    public class AvatarUrls2
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Reporter
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls2 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class Priority
    {
        public string self { get; set; }
        public string iconUrl { get; set; }
        public string name { get; set; }
        public string id { get; set; }
    }

    public class AvatarUrls3
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Author
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls3 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class AvatarUrls4
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class UpdateAuthor
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls4 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class Comment2
    {
        public string self { get; set; }
        public string id { get; set; }
        public Author author { get; set; }
        public string body { get; set; }
        public UpdateAuthor updateAuthor { get; set; }
        public string created { get; set; }
        public string updated { get; set; }
    }

    public class Comment
    {
        public int startAt { get; set; }
        public int maxResults { get; set; }
        public int total { get; set; }
        public List<Comment2> comments { get; set; }
    }

    public class Votes
    {
        public string self { get; set; }
        public int votes { get; set; }
        public bool hasVoted { get; set; }
    }

    public class AvatarUrls5
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Assignee
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls5 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class StatusCategory
    {
        public string self { get; set; }
        public int id { get; set; }
        public string key { get; set; }
        public string colorName { get; set; }
        public string name { get; set; }
    }

    public class Status
    {
        public string self { get; set; }
        public string description { get; set; }
        public string iconUrl { get; set; }
        public string name { get; set; }
        public string id { get; set; }
        public StatusCategory statusCategory { get; set; }
    }

    public class Fields
    {
        public string summary { get; set; }
        public Issuetype issuetype { get; set; }
        public List<object> components { get; set; }
        public string created { get; set; }
        public string description { get; set; }
        public Project project { get; set; }
        public Reporter reporter { get; set; }
        public Priority priority { get; set; }
        public object resolution { get; set; }
        public string duedate { get; set; }
        public Comment comment { get; set; }
        public Votes votes { get; set; }
        public Assignee assignee { get; set; }
        public Status status { get; set; }
    }

    public class Issue
    {
        public string expand { get; set; }
        public string id { get; set; }
        public string self { get; set; }
        public string key { get; set; }
        public Fields fields { get; set; }
    }

    public class RootObject
    {
        public string expand { get; set; }
        public int startAt { get; set; }
        public int maxResults { get; set; }
        public int total { get; set; }
        public List<Issue> issues { get; set; }
    }

var t = JsonConvert.DeserializeObject<RootObject>(json);
var issues = t.issues;
公共类Issuetype
{
公共字符串self{get;set;}
公共字符串id{get;set;}
公共字符串说明{get;set;}
公共字符串iconUrl{get;set;}
公共字符串名称{get;set;}
公共布尔子任务{get;set;}
}
公共类化身
{
公共字符串\uuuu无效\u名称\uuuu48x48{get;set;}
公共字符串uu无效uu名称uuu 24x24{get;set;}
公共字符串uuu无效uuu16x16{get;set;}
公共字符串uuu无效uuu32x32{get;set;}
}
公共类项目
{
公共字符串self{get;set;}
公共字符串id{get;set;}
公共字符串密钥{get;set;}
公共字符串名称{get;set;}
公共化身化身{get;set;}
}
公共类虚拟角色2
{
公共字符串\uuuu无效\u名称\uuuu48x48{get;set;}
公共字符串uu无效uu名称uuu 24x24{get;set;}
公共字符串uuu无效uuu16x16{get;set;}
公共字符串uuu无效uuu32x32{get;set;}
}
公开课记者
{
公共字符串self{get;set;}
公共字符串名称{get;set;}
公共字符串密钥{get;set;}
公共字符串电子邮件地址{get;set;}
公共化身2化身{get;set;}
公共字符串displayName{get;set;}
公共bool活动{get;set;}
公共字符串时区{get;set;}
}
公共类优先级
{
公共字符串self{get;set;}
公共字符串iconUrl{get;set;}
公共字符串名称{get;set;}
公共字符串id{get;set;}
}
公共类ArvarlS3
{
公共字符串\uuuu无效\u名称\uuuu48x48{get;set;}
公共字符串uu无效uu名称uuu 24x24{get;set;}
公共字符串uuu无效uuu16x16{get;set;}
公共字符串uuu无效uuu32x32{get;set;}
}
公共类作者
{
公共字符串self{get;set;}
公共字符串名称{get;set;}
公共字符串密钥{get;set;}
公共字符串电子邮件地址{get;set;}
公共化身s3化身{get;set;}
公共字符串displayName{get;set;}
公共bool活动{get;set;}
公共字符串时区{get;set;}
}
公共类虚拟角色4
{
公共字符串\uuuu无效\u名称\uuuu48x48{get;set;}
公共字符串uu无效uu名称uuu 24x24{get;set;}
公共字符串uuu无效uuu16x16{get;set;}
公共字符串uuu无效uuu32x32{get;set;}
}
公共类更新器
{
公共字符串self{get;set;}
公共字符串名称{get;set;}
公共字符串密钥{get;set;}
公共字符串电子邮件地址{get;set;}
公共化身4化身{get;set;}
公共字符串displayName{get;set;}
公共bool活动{get;set;}
公共字符串时区{get;set;}
}
公开课评论2
{
公共字符串self{get;set;}
公共字符串id{get;set;}
公共作者{get;set;}
公共字符串体{get;set;}
公共UpdateAuthor UpdateAuthor{get;set;}
已创建公共字符串{get;set;}
公共字符串已更新{get;set;}
}
公开课评论
{
public int startAt{get;set;}
public int maxResults{get;set;}
公共整数总计{get;set;}
公共列表注释{get;set;}
}
公众阶级投票
{
公共字符串self{get;set;}
公共整数投票{get;set;}
公共布尔已投票{get;set;}
}
公共类5
{
公共字符串\uuuu无效\u名称\uuuu48x48{get;set;}
公共字符串uu无效uu名称uuu 24x24{get;set;}
公共字符串uuu无效uuu16x16{get;set;}
公共字符串uuu无效uuu32x32{get;set;}
}
公共类受让人
{
公共字符串self{get;set;}
公共字符串名称{get;set;}
公共字符串密钥{get;set;}
公共字符串电子邮件地址{get;set;}
公共化身5化身{get;set;}
公共字符串displayName{get;set;}
公共bool活动{get;set;}
公共字符串时区{get;set;}
}
公共类状态类别
{
公共字符串self{get;set;}
公共int id{get;set;}
公共字符串密钥{get;set;}
公共字符串colorName{get;set;}
公共字符串名称{get;set;}
}
公共阶级地位
{
    public class Issuetype
    {
        public string self { get; set; }
        public string id { get; set; }
        public string description { get; set; }
        public string iconUrl { get; set; }
        public string name { get; set; }
        public bool subtask { get; set; }
    }

    public class AvatarUrls
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Project
    {
        public string self { get; set; }
        public string id { get; set; }
        public string key { get; set; }
        public string name { get; set; }
        public AvatarUrls avatarUrls { get; set; }
    }

    public class AvatarUrls2
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Reporter
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls2 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class Priority
    {
        public string self { get; set; }
        public string iconUrl { get; set; }
        public string name { get; set; }
        public string id { get; set; }
    }

    public class AvatarUrls3
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Author
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls3 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class AvatarUrls4
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class UpdateAuthor
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls4 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class Comment2
    {
        public string self { get; set; }
        public string id { get; set; }
        public Author author { get; set; }
        public string body { get; set; }
        public UpdateAuthor updateAuthor { get; set; }
        public string created { get; set; }
        public string updated { get; set; }
    }

    public class Comment
    {
        public int startAt { get; set; }
        public int maxResults { get; set; }
        public int total { get; set; }
        public List<Comment2> comments { get; set; }
    }

    public class Votes
    {
        public string self { get; set; }
        public int votes { get; set; }
        public bool hasVoted { get; set; }
    }

    public class AvatarUrls5
    {
        public string __invalid_name__48x48 { get; set; }
        public string __invalid_name__24x24 { get; set; }
        public string __invalid_name__16x16 { get; set; }
        public string __invalid_name__32x32 { get; set; }
    }

    public class Assignee
    {
        public string self { get; set; }
        public string name { get; set; }
        public string key { get; set; }
        public string emailAddress { get; set; }
        public AvatarUrls5 avatarUrls { get; set; }
        public string displayName { get; set; }
        public bool active { get; set; }
        public string timeZone { get; set; }
    }

    public class StatusCategory
    {
        public string self { get; set; }
        public int id { get; set; }
        public string key { get; set; }
        public string colorName { get; set; }
        public string name { get; set; }
    }

    public class Status
    {
        public string self { get; set; }
        public string description { get; set; }
        public string iconUrl { get; set; }
        public string name { get; set; }
        public string id { get; set; }
        public StatusCategory statusCategory { get; set; }
    }

    public class Fields
    {
        public string summary { get; set; }
        public Issuetype issuetype { get; set; }
        public List<object> components { get; set; }
        public string created { get; set; }
        public string description { get; set; }
        public Project project { get; set; }
        public Reporter reporter { get; set; }
        public Priority priority { get; set; }
        public object resolution { get; set; }
        public string duedate { get; set; }
        public Comment comment { get; set; }
        public Votes votes { get; set; }
        public Assignee assignee { get; set; }
        public Status status { get; set; }
    }

    public class Issue
    {
        public string expand { get; set; }
        public string id { get; set; }
        public string self { get; set; }
        public string key { get; set; }
        public Fields fields { get; set; }
    }

    public class RootObject
    {
        public string expand { get; set; }
        public int startAt { get; set; }
        public int maxResults { get; set; }
        public int total { get; set; }
        public List<Issue> issues { get; set; }
    }

var t = JsonConvert.DeserializeObject<RootObject>(json);
var issues = t.issues;
var result = JsonConvert.DeserializeObject<RootObject>(myJsonString);
RootObject result = JsonConvert.DeserializeObject<RootObject>(json);

List<string> summaries = new List<string>();
foreach (var item in result.issues)
{
    var summary = item.fields.summary;
    Console.WriteLine(summary);
    summaries.Add(summary);
}