解析后我遇到了这个错误。 * 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSCFString stringValue]:无法识别的选择器发送到实例0x4b68480'
代码是
- (void)解析器:(NSXMLParser *)解析器didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"gallery"]){
}
else if ([elementName isEqualToString:@"asset"]){
NSString *str ;
str = [[attributeDict objectForKey:@"type"] stringValue]; <- HERE
NSLog(@"type = %@",str);
str = [[attributeDict objectForKey:@"thumbnail"] stringValue]; <- HERE
NSLog(@"thumbnail = %@",str);
str = [[attributeDict objectForKey:@"large"] stringValue]; <- HERE
NSLog(@"large = %@",str);
}
NSLog(@"Processing Element: %@",elementName);
}
XML树看起来像
“&lt;”gallery ...“&gt;” “&lt;”asset type =“image”thumbnail =“/ ...”large =“/ ...”“&gt;” ...
谢谢你的帮助!
答案 0 :(得分:0)
错误显然[attributeDict objectForKey:...]
已经返回NSString
。因此,您无需致电stringValue
来存储到str
。即,而不是
str = [[attributeDict objectForKey:@"type"] stringValue];
你可以做到
str = [attributeDict objectForKey:@"type"];