我正在使用 nsxmlparser 解析 rss,我想从 rss 中获取一些图像...我该怎么做?
这是 RSS 的示例
<p><img scr = "IMGURL"></p>
如何获取“IMGURL”
谢谢, TC
最佳答案
这是一个快速技巧 - 仅当您知道字符串不会改变位置时才执行此操作。否则你就有崩溃的风险。
//for demo purposes lets say your <p><img scr = "IMGURL"></p> is a string named sourceString
//chop it up into an array like this and grab it from the arrays position
//create an array
NSArray *tempArray = [sourceString componentsSeparatedByString:@"\""];
//what this has done, it has create an array of objects from your source string separated by "
//so in your tempArray you will have two objects
// objectAtIndex 0 will be: <p><img scr = you wont need this so we can ignore it
// objectAtIndex 1 will be the string you want. it will be: IMGURL
// so now you can quickly create a string from it like this
NSString * imgURL = [[tempArray objectAtIndex:1]description];
这是一个快速而肮脏的伎俩......但它有效!只要数据保持相同的格式即可。你的电话!
关于iphone - NSXMLParser rss 图像 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6865258/