2013-02-28 63 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