美文网首页
iOS---过滤掉json中的html标签

iOS---过滤掉json中的html标签

作者: 鑫飞 | 来源:发表于2017-04-25 14:35 被阅读94次

html标签:如 </span></span></p>

[self flattenHTML:str];
//方法
- (NSString *)flattenHTML:(NSString *)html { 
    NSScanner *theScanner; 
    NSString *text = nil; 搜索
 theScanner = [NSScanner scannerWithString:html]; 
while ([theScanner isAtEnd] == NO) { 
        // find start of tag 
        [theScanner scanUpToString:@"<" intoString:NULL] ; 
        // find end of tag 
        [theScanner scanUpToString:@">" intoString:&text] ; 
        // replace the found tag with a space 
        //(you can filter multi-spaces out later if you wish) 
        html = [html stringByReplacingOccurrencesOfString: 
                [NSString stringWithFormat:@"%@>", text] 
                                               withString:@""]; 
 } // while // 
    NSLog(@"-----===%@",html); 
    return html; 
}

相关文章

网友评论

      本文标题:iOS---过滤掉json中的html标签

      本文链接:https://www.haomeiwen.com/subject/gievzttx.html