2014-01-06 151 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"]