JIRA REST API,JSON响应,C#

JIRA REST API,JSON响应,C#,c#,json,rest,jira,jira-rest-api,C#,Json,Rest,Jira,Jira Rest Api,我想从董事会获取问题并打印问题摘要(使用jirarestapi:),但我不想获取所有问题的字段,我需要字段:“sprint”和“epic” 我有一个错误: 未处理的异常:System.NullReferenceException:对象引用 未设置为对象的实例 第行: var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, @"/rest/a

我想从董事会获取问题并打印问题摘要(使用jirarestapi:),但我不想获取所有问题的字段,我需要字段:“sprint”和“epic”

我有一个错误:

未处理的异常:System.NullReferenceException:对象引用 未设置为对象的实例

第行:

var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                        @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
var response=client.RestClient.ExecuteRequest(Method.GET,
@“/rest/agile/1.0/board/2/issue?fields='epic,sprint'”;
代码(C#):

var client=Atlassian.Jira.Jira.CreateRestClient(jiraurl,登录名,密码);
var response=client.RestClient.ExecuteRequest(Method.GET,
@“/rest/agile/1.0/board/2/issue?fields='epic,sprint'”;
foreach(风险值问题响应。问题)
{
Console.WriteLine(issue.fields.epic.summary);
}
课堂反应(C#):

公共类响应
{
公共字符串扩展;
公共int startAt;
公共结果;
公共整数合计;
公开名单问题;
}    
公共类问题_
{
公共字符串扩展;
公共字符串id;
公共字符串自身;
公共字符串密钥;
公共领域;
}    
公共类字段
{
公共短跑;
公共史诗;
}   
公共级短跑
{
公共int id;
公共字符串自身;
公共字符串状态;
公共字符串名称;
}    
公共级史诗
{
公共int id;
公共字符串自身;
公共字符串名称;
公共字符串摘要;
公共色彩;
公共事业已完成;
}    
公共类颜色
{
公共字符串密钥;
}
简单地旅行“问题”=>“字段”得到了您的“冲刺”和“史诗”。

var response=client.RestClient.ExecuteRequest(Method.GET,
@“/rest/agile/1.0/board/2/issue?fields='epic,sprint'”;
var jo=JObject.Parse(响应);
var id=jo[“问题”][“字段”]['sprint']['id'].ToString();
var self=jo[“问题”][“字段”]['sprint']['self'].ToString();
var state=jo[“问题”][“字段”][“冲刺”][“状态”]。ToString();
var name=jo[“问题”][“字段”][“冲刺”][“名称”]。ToString();
控制台写入线(id);
控制台写入线(self);
控制台写入线(状态);
Console.WriteLine(名称);
Console.Read();

似乎有些东西没有正确初始化。每当这种情况发生在我身上,我都会用赋值来打破这个链条,试图找出哪个对象是空的。还要捕获异常,并在VisualStudio中进行探索。在您的情况下,请尝试以下方法:

try{
  var client = Atlassian.Jira.Jira.CreateRestClient(jiraurl, login, password);
  // Add breakpoint... is client null? There could be an issue with your login, password or the url you've passed. 
  // Or maybe it's Atlassian.Jira.CreateRestClient (instead of Jira.Jira.CreateRestClient), though that should get flagged by the compiler unless there's some recursion or parenting in the Jira namespace
  var restClient = client.RestClient; 
  // Add breakpoint... is restClient null? Could be that CreateRestClient is lazy-loading, in which case I'd look at the url, login and password again.
  var response = restClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                   @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
}
catch(Exception ex)
{
  Console.WriteLine(ex); // Or just breakpoint here and explore the exception.
}
试试看{
var client=Atlassian.Jira.Jira.CreateRestClient(jiraurl,登录名,密码);
//添加断点…客户端是否为空?您的登录名、密码或传递的url可能存在问题。
//或者它可能是Atlassian.Jira.CreateRestClient(而不是Jira.Jira.CreateRestClient),尽管编译器应该标记它,除非Jira命名空间中存在递归或父代
var restClient=client.restClient;
//添加断点…restClient是否为空?可能是CreateRestClient是延迟加载,在这种情况下,我会再次查看url、登录名和密码。
var response=restClient.ExecuteRequest(Method.GET,
@“/rest/agile/1.0/board/2/issue?fields='epic,sprint'”;
}
捕获(例外情况除外)
{
Console.WriteLine(ex);//或者只在此处断点并探索异常。
}

如果你读了我的代码,你会看到-我会做。但我不知道我做错了什么。:\n您可以启用请求跟踪:无论如何,您可以检查哪些值为null吗?是RestClient、response还是其他什么?可能因为某些错误的结果,您无法将结果反序列化为“ResponseIssues”。@kat1330,我无法获取“文件”中的所有内容。我尝试获取“description”,但得到错误:“Object reference未设置为对象的实例”。这对OP没有帮助,因为第一行是发生null reference异常的地方。null reference异常位于:“Console.WriteLine(issue.fields.epic.summary);“thnx,我发现错误:它不在代码中,在jira发行版中没有Sprint。我无法获得“文件”中的所有内容。我尝试获取“描述”,但得到错误:“对象引用未设置为对象的实例。”
public class ResponseIssues
{
    public string expand;
    public int startAt;
    public int maxResults;
    public int total;
    public List<Issue_> issues;
}    
public class Issue_
{
    public string expand;
    public string id;
    public string self;
    public string key;
    public Field fields;
}    
public class Field
{
    public Sprint sprint;
    public Epic epic;            
}   
public class Sprint
{
    public int id;
    public string self;
    public string state;
    public string name;
}    
public class Epic
{
    public int id;
    public string self;
    public string name;
    public string summary;
    public Color color;
    public bool done;
}    
public class Color
{
    public string key;
}
 var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                        @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
            var jo = JObject.Parse(response);
            var id = jo["issues"]["fields"]['sprint']['id'].ToString();
            var self= jo["issues"]["fields"]['sprint']['self'].ToString();
            var state= jo["issues"]["fields"]['sprint']['state'].ToString();
            var name= jo["issues"]["fields"]['sprint']['name'].ToString();
            Console.WriteLine(id);
            Console.WriteLine(self);
            Console.WriteLine(state);
            Console.WriteLine(name);
            Console.Read();
try{
  var client = Atlassian.Jira.Jira.CreateRestClient(jiraurl, login, password);
  // Add breakpoint... is client null? There could be an issue with your login, password or the url you've passed. 
  // Or maybe it's Atlassian.Jira.CreateRestClient (instead of Jira.Jira.CreateRestClient), though that should get flagged by the compiler unless there's some recursion or parenting in the Jira namespace
  var restClient = client.RestClient; 
  // Add breakpoint... is restClient null? Could be that CreateRestClient is lazy-loading, in which case I'd look at the url, login and password again.
  var response = restClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                   @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
}
catch(Exception ex)
{
  Console.WriteLine(ex); // Or just breakpoint here and explore the exception.
}