如何使用 NSMutableDictionary 解析图像?

发布于 2024-10-01 08:47:35 字数 2224 浏览 1 评论 0原文

我需要帮助使用字典解析图像。我可以使用字典获取文本数据,但无法使用字典解析相应内容的图像,这里是我的代码

   -(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2024-10-08 08:47:35

最后我找到了答案,小错误是我解析标签而不是 url

感谢您的帮助

finally i found answer small mistake is I parse the tag instead of url

Thanks for the help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文