NSXMLParser 解析使用 Windows-1256 编码的 xml 文件
我想解析 Windows-1256" 编码的 rss 文件,但解析器没有读取它 我用 UTF8 编码做了很多解析,但只有这个不起作用,为什么?
已解决 解决方案是
NSString *myStr = [[NSString alloc] initWithData:myData encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic) ];
myStr = [myStr stringByReplacingOccurrencesOfString:@"encoding=\"windows-1251\"" withString:@""];
NSData* aData = [myStr dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:aData];
i want to parse rss file in Windows-1256" encoding but it is not being read by parser
i done alot of parsing in UTF8 encoding but only this don't work why?
Solved
solution is
NSString *myStr = [[NSString alloc] initWithData:myData encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic) ];
myStr = [myStr stringByReplacingOccurrencesOfString:@"encoding=\"windows-1251\"" withString:@""];
NSData* aData = [myStr dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:aData];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在
NSXMLParser
委托中实现parseErrorOccurred:
方法,它将为您提供错误的确切原因。像这样的东西:
If you implement the
parseErrorOccurred:
method in yourNSXMLParser
delegate, it will give you the exact reason for the errors.Something like:
谢谢 Mohamed 的回答,我已经研究了 10 天,但根本没有找到答案。这是我的代码:
}
Thank you Mohamed for the answer I kept working on it for 10 days and we found no answers at all. This is my code:
}
你也可以尝试这个:
Also you can try this: