首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回null的null

返回null的null
EN

Stack Overflow用户
提问于 2013-09-12 13:14:03
回答 1查看 284关注 0票数 1

我在查询一个PortfolioItem/Mmf。这样做很好:

代码语言:javascript
复制
new Request("PortfolioItem/Mmf")
            {
                ProjectScopeUp = false,
                ProjectScopeDown = true,
                Fetch = new List() { "Name", "Description", "FormattedID", "LastUpdateDate", "Owner", "Children" },
                Query = new Query("FormattedID", Query.Operator.Equals, _formattedID)
            };

但是,当我查询参考地址(我可以在浏览器上打开这个地址并完美地检查json )时,如下所示:

代码语言:javascript
复制
//_childFetch contains the same Fetch string list from the previous query
var childObject = m_rallyApi.GetByReference(_childRef, _childFetch);

它返回null。

为什么这不管用?当这是一个层次化的需求时,这两个查询都可以工作。

使用()编辑方法的完整代码

代码语言:javascript
复制
private HierarchicalRequirement GetUserStoryByReference(string _childRef, string[] _childFetch)
        {
            HierarchicalRequirement userStory = null;

            var childObject = m_rallyApi.GetByReference(_childRef, _childFetch);

            if (childObject["Children"].Count == 0)
            {
                userStory = new HierarchicalRequirement(childObject);
            }
            else
            {
                if (childObject["Children"].Count > 0)
                {
                    userStory = new HierarchicalRequirement(childObject);

                    foreach (var child in childObject["Children"])
                    {
                        userStory.Children.Add(GetUserStoryByReference(child["_ref"], _childFetch));
                    }
                }
            }
            return userStory;
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-16 16:32:54

我提交了一个缺陷。我得到了

代码语言:javascript
复制
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.

使用时

代码语言:javascript
复制
String featureRef = queryResults.Results.First()._ref; 
Console.WriteLine(featureRef); //prints correctly
DynamicJsonObject feature = restApi.GetByReference(featureRef, "Name");
String name = feature["Name"];

最后一行是它窒息的地方。与UserStories及其子代码相同的代码工作。

如果我避免使用GetByReference,那么它可以与PortfolioItems一起工作。以下是代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;

namespace FindTFchildren
{
    class Program
    {
        static void Main(string[] args)
        {
            RallyRestApi restApi;
            restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");

            String projectRef = "/project/12352814790";     //replace this OID with an OID of your project


            Request fRequest = new Request("PortfolioItem/Feature");
            fRequest.Project = projectRef;
            fRequest.Workspace = workspaceRef;
            fRequest.Fetch = new List<string>() { "FormattedID", "Name", "UserStories"};
            fRequest.Query = new Query("FormattedID", Query.Operator.Equals, "F3");
            QueryResult queryResults = restApi.Query(fRequest);


            foreach (var f in queryResults.Results)
            {
                Console.WriteLine("FormattedID: " + f["FormattedID"] + " Name: " + f["Name"]);
                Console.WriteLine("Collection ref: " + f["UserStories"]._ref);
                Request childrenRequest = new Request(f["UserStories"]);
                QueryResult queryChildrenResult = restApi.Query(childrenRequest);
                foreach (var c in queryChildrenResult.Results)
                {
                    Console.WriteLine("FormattedID: " + c["FormattedID"] + " Name: " + c["Name"]);
                }

            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18765353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档