0

我正在练习 RESTKit,所以我正在构建一个 Dribbble 客户端来掌握 REST,我成功获得了 XML 响应,但是当我使用 NSXMLParser 解析它时,它记录开始,然后立即停止,我该如何修复它,或者只是让 XML 更容易区分哪个项目是哪个项目,然后将其放入我的表中?

继承人的代码:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    NSLog(@"I just found a start tag for %@",elementName);

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    NSLog(@"the parser just found this text in a tag:%@",string);
}

-(void)parserDidStartDocument:(NSXMLParser *)parser {
    NSLog(@"starting");
}

-(void)parserDidEndDocument:(NSXMLParser *)parser {
    NSLog(@"end");
}

-(IBAction)test {
    [[RKClient sharedClient] get:@"/shots/popular" delegate:self];
}

-(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
    if ([request isGET]) {

        NSLog(@"Retrieved XML: %@", [response bodyAsString]);
        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[response body]];
        [xmlParser setDelegate:self];
        [xmlParser parse];
    }
    else if ([request isPOST]) {


        if ([response isJSON]) {

            NSLog(@"Got a JSON response back from our POST!");
        }


    }
    else if ([request isDELETE]) {

        if ([response isNotFound]) {
            NSLog(@"The resource path '%@' was not found.", [request resourcePath]);
        }


    }
}
4

1 回答 1

0

您从解析器得到的错误是NSXMLParserEmptyDocumentError. 似乎您没有从服务器获得预期的响应;这不是解析器的问题。

您应该检查连接或响应是否发生错误,并且结果实际上是一个 XML 文档。

于 2012-07-02T01:01:39.970 回答