【问题标题】:TouchXML to read in twitter feed for iphone appTouchXML 读取 iPhone 应用程序的 twitter 提要
【发布时间】:2010-05-18 10:13:32
【问题描述】:

所以我已经设法从 twitter 获取提要并尝试解析它...... 我只需要提要中的以下字段: 名称、描述、time_zone 和 created_at 我成功提取了名称和描述.. 但是 time_zone 和 created_at 总是为零...以下是代码...

有人知道为什么这可能不起作用吗?

-(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];

}

提前感谢您的帮助!!

菲奥娜

【问题讨论】:

    标签: iphone xcode touchxml


    【解决方案1】:

    可能是个错误,但为什么它们是双等号 (==),通常用于条件检查

    【讨论】:

    • 谢谢一百万..我已经盯着它看了很久,现在我觉得真的很愚蠢......但再次感谢!!
    • Np,我通常反过来做,并在 if 语句中分配一些东西,想知道为什么它总是正确的。快乐编码
    猜你喜欢
    • 2011-08-26
    • 2012-04-25
    • 2011-08-22
    • 2011-11-30
    • 2012-04-27
    • 1970-01-01
    • 2011-11-03
    • 2012-09-09
    • 1970-01-01
    相关资源
    最近更新 更多