我正在使用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];


这是一个快速而肮脏的把戏...但是它有效!只要数据保持相同的格式。您的来电!

10-07 19:56
查看更多