如何使用 NSMutableDictionary 解析图像?
我需要帮助使用字典解析图像。我可以使用字典获取文本数据,但无法使用字典解析相应内容的图像,这里是我的代码
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"title"]) {
item = [[NSMutableDictionary alloc] init];
ktitle = [[NSMutableString alloc] init];
kpubdate = [[NSMutableString alloc] init];
kitem = [[NSMutableString alloc] init];
//kmedia = [[UIImageView alloc] init];
klink = [[NSMutableString alloc] init];
kdescription = [[NSMutableString alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"title"]) {
[item setObject:ktitle forKey:@"title"];
[item setObject:klink forKey:@"link"];
[item setObject:kdescription forKey:@"description"];
[item setObject:kpubdate forKey:@"pubDate"];
//kmedia = [[UIImageView alloc] initWithImage:[UIImage keyPathsForValuesAffectingValueForKey:@"media:content"]];
//[item setObject:kmedia forKey:@"media:content"];
[arrayList addObject:[item copy]];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if([currentElement isEqualToString:@"title"]){
[ktitle appendString:string];
}
else if ([currentElement isEqualToString:@"link"]) {
[klink appendString:string];
}
else if([currentElement isEqualToString:@"description"]){
[kdescription appendString:string];
}
}
I need help for parsing the image using dictionary. i can get the text data using dictionary but can't parse the image of the corresponding content using dictionary here my code
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"title"]) {
item = [[NSMutableDictionary alloc] init];
ktitle = [[NSMutableString alloc] init];
kpubdate = [[NSMutableString alloc] init];
kitem = [[NSMutableString alloc] init];
//kmedia = [[UIImageView alloc] init];
klink = [[NSMutableString alloc] init];
kdescription = [[NSMutableString alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"title"]) {
[item setObject:ktitle forKey:@"title"];
[item setObject:klink forKey:@"link"];
[item setObject:kdescription forKey:@"description"];
[item setObject:kpubdate forKey:@"pubDate"];
//kmedia = [[UIImageView alloc] initWithImage:[UIImage keyPathsForValuesAffectingValueForKey:@"media:content"]];
//[item setObject:kmedia forKey:@"media:content"];
[arrayList addObject:[item copy]];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if([currentElement isEqualToString:@"title"]){
[ktitle appendString:string];
}
else if ([currentElement isEqualToString:@"link"]) {
[klink appendString:string];
}
else if([currentElement isEqualToString:@"description"]){
[kdescription appendString:string];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我找到了答案,小错误是我解析标签而不是 url
感谢您的帮助
finally i found answer small mistake is I parse the tag instead of url
Thanks for the help