JIRA REST API,JSON响应,C#

时间:2016-10-26 18:45:44

标签: c# json rest jira jira-rest-api

我想从主板和打印问题的摘要中获取问题(使用JIRA Rest API:https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-getIssuesForBoard),但我不想获得所有问题的字段, - 我需要字段:" sprint"和#34;史诗"。

我有错误:

  

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

在线:

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

代码(C#):

var client = Atlassian.Jira.Jira.CreateRestClient(jiraurl, login, password);
var response = client.RestClient.ExecuteRequest<ResponseIssues>(Method.GET, 
                       @"/rest/agile/1.0/board/2/issue?fields='epic,sprint'");
foreach (var issue in response.issues)
{
     Console.WriteLine(issue.fields.epic.summary);
}

类ResponseIssues(C#):

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;
}

3 个答案:

答案 0 :(得分:1)

似乎没有正确初始化的东西。每当发生这种情况时,我会通过赋值来分解链,以试图找出哪个对象为空。还可以捕捉异常,并在visual studio中进行探索。在你的情况下,试试这个:

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.
}

答案 1 :(得分:0)

简单地旅行&#34;问题&#34; =&gt;&#34;字段&#34;得到了你的&#34; sprint&#34;和#34;史诗&#34;。

答案 2 :(得分:0)

<asp:DropDownList ID="StudentsList" AutoPostBack="True" OnSelectedIndexChanged="LoadStudents">...</asp>DropDownList>