[2014-04-20]ios获取数据中去掉htm…
来源:互联网 发布:淘宝的港货可以买吗? 编辑:程序博客网 时间:2024/04/30 08:30
最近在工作中遇到后台返回的json串带有html标签,为此找到了相应的方法去掉标签,目前测试所有标签均能去掉,如有不能的请告知。
html为json串中带有html标签的string类型。
- NSScanner
*theScanner = [NSScanner scannerWithString:html]; -
NSString *text = nil; -
-
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 stringByReplacingOccurre ncesOfString: -
[ NSString stringWithFormat:@"%@>", text] -
withString:@""];
如果解析出来还带有\n \t \r之类的再在此基础上用""替代掉。如下:
- NSMutableString *s = [NSMutableStringstringWithString:
html ]; -
[sreplaceOccurrencesOfStri ng:@“ “ withString:@“”options:NSCaseInsensitiveSearch range:NSMakeRange(0, [slength])]; -
[sreplaceOccurrencesOfStri ng:@“\\r” withString:@“”options:NSCaseInsensitiveSearch range:NSMakeRange(0, [slength])]; -
[sreplaceOccurrencesOfStri ng:@“\t” withString:@“”options:NSCaseInsensitiveSearch range:NSMakeRange(0, [slength])]; -
[sreplaceOccurrencesOfStri ng:@“\\n” withString:@“”options:NSCaseInsensitiveSearch range:NSMakeRange(0, [slength])]; -
[sreplaceOccurrencesOfStri ng:@“+” withString:@“”options:NSCaseInsensitiveSearch range:NSMakeRange(0, [slength])];
0 0
- [2014-04-20]ios获取数据中去掉htm…
- HTM 11.0中MV的获取
- 去掉对象中重复数据
- 去掉返回数据字符中“/”
- iOS 获取去掉空格的字符串长度
- JAVA中利用Htmlparse解析HTM…
- ios开发从.plist文件中获取数据
- IOS之从plist文件中获取数据
- 【iOS】字符串NSString中去掉空格
- 【iOS】字符串NSString中去掉空格
- 【iOS】字符串NSString中去掉空格
- 【iOS】字符串NSString中去掉空格
- iOS:iOS8中UITableView去掉左侧margin
- iOS release版本中去掉NSLog输出
- iOS 去掉字符串中两头的尖括号
- iOS 字符串NSString中去掉空格
- iOS中如何去掉cell分割线
- iOS 去掉字符串中特殊字符
- 2014年03月30日
- [2014-03-31]使用NSOperationQueue…
- [2014-03-31]
- [2014-04-10]unable to …
- [2014-04-16]Pod::Executable&nbsp…
- [2014-04-20]ios获取数据中去掉htm…
- [2014-04-21]解决uitableviewcell…
- iOS 开发者必知的 75&nb…
- ios支付宝Demo报错(Linker co…
- [2014-06-01][转]apps须遵循iOS数…
- [2014-09-25]对于Xcode6里面反射(p…
- [2014-10-09]Xcode6更新之后的一些…
- [2014-10-20]XCode6编译问题:fata…
- XCode报错 has been&nbs…