2014-01-06 185 views
0

我使用objectForKeyxml文件中獲取價值,但不是其失敗。這裏是xml數據iOS-無法獲得價值

{ 
"__name" = root; 
destination = CIVC; 
message =  { 
    "co2_emissions" = "<p>CO<sub>2</sub> emissions saved by this BART trip: <strong>9.8 pounds.</strong> <a href=\"http://www.bart.gov/guide/carbon.aspx\">Read more</a></p>"; 
    legend = "bikeflag: 1 = bikes allowed. 0 = no bikes allowed. transfercode: blank = no transfer, N = normal transfer, T = timed transfer, connecting trains will wait up to five minutes for transferring passengers. S = scheduled transfer, connecting trains will not wait for transferring passengers if there is a delay."; 
}; 
origin = ASHB; 
"sched_num" = 34; 
schedule =  { 
    after = 2; 
    before = 2; 
    date = "Jan 6, 2014"; 
    request =   { 
     trip =    (
          { 
       "_clipper" = "1.40"; 
       "_destTimeDate" = "01/06/2014"; 
       "_destTimeMin" = "11:52 AM"; 
       "_destination" = CIVC; 
       "_fare" = "3.75"; 
       "_origTimeDate" = "01/06/2014 "; 
       "_origTimeMin" = "11:27 AM"; 
       "_origin" = ASHB; 
       leg =      { 
        "_bikeflag" = 1; 
        "_destTimeDate" = "01/06/2014"; 
        "_destTimeMin" = "11:52 AM"; 
        "_destination" = CIVC; 
        "_line" = "ROUTE 7"; 
        "_order" = 1; 
        "_origTimeDate" = "01/06/2014"; 
        "_origTimeMin" = "11:27 AM"; 
        "_origin" = ASHB; 
        "_trainHeadStation" = MLBR; 
        "_trainIdx" = 29; 
        "_transfercode" = ""; 
       }; 
      }, 

和這裏的部分是我的代碼,以獲得origindestinationsched_numdate_destTimeDate origindestinationsched_numdate做工精良只有

self.DepartLabel.text = [dic objectForKey:@"origin"]; 
self.ArriveLabel.text = [dic objectForKey:@"destination"]; 
self.SchednumLabel.text = [dic objectForKey:@"sched_num"]; 
self.DateLabel.text = [[dic objectForKey:@"schedule"] objectForKey:@"date"]; 
self.TimeLabel.text = [[[[dic objectForKey:@"schedule"] objectForKey:@"request"]objectForKey:@"trip"]objectForKey:@"_destTimeDate"]; 

_destTimeDate行的事工作。如何獲得這個值?

+0

請注意,IOS是不一樣的iOS。 IOS代表http://en.wikipedia.org/wiki/Cisco_IOS,而iOS則代表http://en.wikipedia.org/wiki/IOS – Popeye

回答

1

如果這是你的NSDictionary的輸出,那麼你需要抓住第一個索引。

self.TimeLabel.text = [[[[[dic objectForKey:@"schedule"] objectForKey:@"request"] objectForKey:@"trip"] objectAtIndex:0 ] objectForKey:@"_destTimeDate"]; 

或馬丁 - [R指出,你可以像這樣做,以及

dic[@"schedule"][@"request"][@"trip"][0][@"_destTimeDate"]