NSString的多个URL字符串的分割和截取技巧
2015-01-06 15:56
211 查看
今天开发高德云图,返回来的image是字符串组,不是Json,也不是字典,我的妈啊!你说的是真的!
我现在想要分割他们,并放到不同的数值或字典,直接上方法。【ps:我不知道有没有更好的方法,还有这个方法的性能如何,唉,要学习的太多,我还得慢慢来,虚心吧!少年!】
有必要解释一下吗?
我的思路是,先以“}”,分割字符串,得到的数组,在一个一个的截取~~
nice~
preurl=( { "_id" = 54a358f2e4b053daeaf71fb7; "_preurl" = "http://img.yuntu.amap.com/54a358f2e4b053daeaf71fb7@!thumb"; "_url" = "http://img.yuntu.amap.com/54a358f2e4b053daeaf71fb7@!orig"; }, { "_id" = 54a36713e4b053daeaf7213e; "_preurl" = "http://img.yuntu.amap.com/54a36713e4b053daeaf7213e@!thumb"; "_url" = "http://img.yuntu.amap.com/54a36713e4b053daeaf7213e@!orig"; }, { "_id" = 54ab7e91e4b053daeaf7c7ea; "_preurl" = "http://img.yuntu.amap.com/54ab7e91e4b053daeaf7c7ea@!thumb"; "_url" = "http://img.yuntu.amap.com/54ab7e91e4b053daeaf7c7ea@!orig"; }, { "_id" = 54ab7e97e4b053daeaf7c7ed; "_preurl" = "http://img.yuntu.amap.com/54ab7e97e4b053daeaf7c7ed@!thumb"; "_url" = "http://img.yuntu.amap.com/54ab7e97e4b053daeaf7c7ed@!orig"; }, { "_id" = 54ab7e9de4b053daeaf7c7ef; "_preurl" = "http://img.yuntu.amap.com/54ab7e9de4b053daeaf7c7ef@!thumb"; "_url" = "http://img.yuntu.amap.com/54ab7e9de4b053daeaf7c7ef@!orig"; }, { "_id" = 54ab7ea6e4b053daeaf7c7f1; "_preurl" = "http://img.yuntu.amap.com/54ab7ea6e4b053daeaf7c7f1@!thumb"; "_url" = "http://img.yuntu.amap.com/54ab7ea6e4b053daeaf7c7f1@!orig"; } )
我现在想要分割他们,并放到不同的数值或字典,直接上方法。【ps:我不知道有没有更好的方法,还有这个方法的性能如何,唉,要学习的太多,我还得慢慢来,虚心吧!少年!】
//从数据中分段 NSArray *arry=[imageStr componentsSeparatedByString:@"}"]; for (int i = 0;i < arry.count -1;i++) { NSString * imageStrring = arry[i]; //去掉所以换行 //imageStr = [imageStr stringByReplacingOccurrencesOfString:@"\n" withString:@""]; //去掉所有空格 imageStr = [imageStr stringByReplacingOccurrencesOfString:@" " withString:@""]; NSString * preurl = (NSString *) [[[[imageStrring componentsSeparatedByString:@"preurl\"=\""] objectAtIndex:1] componentsSeparatedByString:@"\";"] objectAtIndex:0]; //NSLog(@"\n %@ \n",preurl); [self.thumbPhotosUrlArray addObject:preurl]; NSString * url = (NSString *) [[[[imageStrring componentsSeparatedByString:@"_url\"=\""] objectAtIndex:1] componentsSeparatedByString:@"\";"] objectAtIndex:0]; [self.origPhotosUrlArray addObject:url]; //NSLog(@"\n %@ \n",url); }
有必要解释一下吗?
我的思路是,先以“}”,分割字符串,得到的数组,在一个一个的截取~~
nice~
相关文章推荐
- Objectvie-C之 NSString 处理技巧-分割字符串
- JS截取与分割字符串常用技巧总结
- JS截取与分割字符串常用技巧总结
- Objectvie-C之 NSString 处理技巧<一>:分割字符串
- NSString 处理技巧:分割字符串
- JS截取与分割字符串常用技巧总结
- JS截取与分割字符串常用技巧总结
- JS截取与分割字符串常用技巧总结
- 截取字符串最后一个字符 && asp textarea 多行数组分割处理
- Javascript 获取链接(url)参数的方法[正则与截取字符串]
- [转]java截取字符串,截串,substring和split,分割字母和数字,正则缝隙
- Python 字符串操作(截取/替换/查找/分割)
- C#字符串截取,字符串分割
- NSString的搜索字符串 截取 抽取
- 根据字数截取字符串,不能截断url
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- NSString 截取字符串的某一个部分
- 黄聪:Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 自己实现的一个字符串分割截取函数,以及查找指定字符
- js 日期字符串截取分割成单个具体的日期