2013-02-28 53 views
0

我有问题进入另一个NSDictionary内的NSDictionary。我一直在尝试访问关键nodeChildArray的第0个索引中的nodeContent键“使用设施的用户数量:163”中的文本。这是数组。无法访问字典内的对象

{ 
nodeAttributeArray =  (
      { 
     attributeName = class; 
     nodeContent = style1; 
    } 
); 
nodeChildArray =  (
      { 
     nodeContent = "Number of Patrons Using Facility: 163"; 
     nodeName = text; 
    }, 
      { 
     nodeName = br; 
    }, 
      { 
     nodeContent = " 
     Room Occupancy: 210 "; 
     nodeName = text; 
    }, 
      { 
     nodeName = br; 
    }, 
      { 
     nodeContent = " 
     Current Wait: 0 minutes "; 
     nodeName = text; 
    } 
); 
nodeName = p; 
} 

我曾尝试以下的不同变化:所以应该在索引中返回两个按键

//I Parse some HTML using Xpath before this 
NSArray *tutorialsNodes = [tutorialsParser  
searchWithXPathQuery:tutorialsXpathQueryString]; 

NSDictionary*dict=[tutorialsNodes objectAtIndex:0]; 
NSDictionary*dict2=[[dict objectForKey:@"nodeChildArray"]objectAtIndex:0]; 

但它一直返回null。我真的很感谢一些帮助。谢谢!

+0

所以'dict'不是零和'dict2'是零? – Sebastian 2013-02-28 21:48:10

+0

这是正确的,字典不是零,但字典2是零。我不确定发生了什么事。下面的答案似乎也不起作用。 – pj409 2013-02-28 23:18:29

回答

0

MainResultDictionary =>包含您回应

你应该在代码

NSArray *dictsArr = [MainResultDictionary objectForkey:@"nodeChildArray"]; 
NSdictionary *dict = [dictsArr objectAtIndex:0]; 
[dict objectForkey:@"nodeContent"]; 
+0

我很欣赏它,但它仍然不起作用,结果是(null) – pj409 2013-02-28 23:18:50

+0

为什么它不起作用?你如何得到结果?你能分享代码吗? – yunas 2013-03-01 11:58:00

+0

事实证明,NSArray'tutorialNodes'是一个TFHippleElement,而不是一个数组。该代码返回null,因为字典行为更像一个字符串......没有键@“nodeChildArray”。为了解决这个问题,我不得不使用不同的HTML解析器,而不是Hipple – pj409 2013-03-04 15:16:48