2010-05-18 34 views
0

所以我設法從Twitter獲取飼料,並試圖解析它... 我只需要飼料中的以下領域: 名稱,描述,time_zone和created_at 我成功拔出名稱和說明..但是time_zone和created_at總是零...以下是代碼...TouchXML閱讀Twitter的飼料iphone應用程序

任何人都可以看到爲什麼這可能不起作用?

-(void) friends_timeline_callback:(NSData *)data{ 

    NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; 
    NSLog(@"Data from twitter: %@", string); 

    NSMutableArray *res = [[NSMutableArray alloc] init]; 
    CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease]; 
    NSArray *nodes = nil; 

    //! searching for item nodes 
    nodes = [doc nodesForXPath:@"/statuses/status/user" error:nil]; 

    for (CXMLElement *node in nodes) 
    { 
     int counter; 
     Contact *contact = [[Contact alloc] init]; 

     for (counter = 0; counter < [node childCount]; counter++) 
     { 
      //pulling out name and description only for the minute!!! 
      if ([[[node childAtIndex:counter] name] isEqual:@"name"]){ 
       contact.name = [[node childAtIndex:counter] stringValue]; 

      }else if ([[[node childAtIndex:counter] name] isEqual:@"description"]) { 

       // common procedure: dictionary with keys/values from XML node 
       if ([[node childAtIndex:counter] stringValue] == NULL){ 
        contact.nextAction = @"No description"; 
       }else{ 
        contact.nextAction = [[node childAtIndex:counter] stringValue]; 
       } 

      }else if ([[[node childAtIndex:counter] name] isEqual:@"created_at"]){ 

       contact.date == [[node childAtIndex:counter] stringValue]; 

      }else if([[[node childAtIndex:counter] name] isEqual:@"time_zone"]){ 

       contact.status == [[node childAtIndex:counter] stringValue]; 
       [res addObject:contact]; 
       [contact release]; 
      } 
     } 
    } 
    self.contactsArray = res; 
    [res release]; 
    [self.tableView reloadData]; 

} 

在此先感謝您的幫助!

菲奧娜

回答

1

可能是一個錯誤,但他們爲什麼雙等於(==),通常用於健康檢查

+0

太感謝了..我一直在盯着那個好久,現在我感覺真的很愚蠢......但再次感謝! – Fiona 2010-05-18 11:04:00

+0

Np,我通常是這樣做的,並在if語句中分配一些內容,並想知道爲什麼它總是如此。快樂的編碼 – Rudiger 2010-05-18 11:07:09