1. 程式人生 > >NSString的多個URL字串的分割和擷取技巧

NSString的多個URL字串的分割和擷取技巧

今天開發高德雲圖,返回來的image是字串組,不是Json,也不是字典,我的媽啊!你說的是真的!

preurl=(

        {

        "_id" = 54a358f2e4b053daeaf71fb7;

        "_preurl" = "http://img.yuntu.amap.com/[email protected]!thumb";

        "_url" = "http://img.yuntu.amap.com/[email protected]!orig";

    },

        {

        "_id" = 54a36713e4b053daeaf7213e;

        "_preurl" = "http://img.yuntu.amap.com/
[email protected]
!thumb"; "_url" = "http://img.yuntu.amap.com/[email protected]!orig"; }, { "_id" = 54ab7e91e4b053daeaf7c7ea; "_preurl" = "http://img.yuntu.amap.com/[email protected]!thumb"; "_url" = "http://img.yuntu.amap.com/[email protected]
!orig"; }, { "_id" = 54ab7e97e4b053daeaf7c7ed; "_preurl" = "http://img.yuntu.amap.com/[email protected]!thumb"; "_url" = "http://img.yuntu.amap.com/[email protected]!orig"; }, { "_id" = 54ab7e9de4b053daeaf7c7ef; "_preurl" = "http://img.yuntu.amap.com/
[email protected]
!thumb"; "_url" = "http://img.yuntu.amap.com/[email protected]!orig"; }, { "_id" = 54ab7ea6e4b053daeaf7c7f1; "_preurl" = "http://img.yuntu.amap.com/[email protected]!thumb"; "_url" = "http://img.yuntu.amap.com/[email protected]!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~

相關推薦

NSStringURL字串分割擷取技巧

今天開發高德雲圖,返回來的image是字串組,不是Json,也不是字典,我的媽啊!你說的是真的! preurl=( { "_id" = 54a358f2e4b053daeaf71fb7; "_preurl" = "h

filter配置url-pattern排除個別servlet

                最近做專案遇到一個Filter需要配置多個url-pattern,上網查了下資料,經測試,現總結下

MFC將edit編輯框內的字串,根據“\n”換行符分割單行字串

程式碼功能:獲取到edit編輯框內的多行內容,並將其分割成多個單行字串 作者:weekdawn //獲取編輯框內容 UpdateData(TRUE); CString strEditStr;//編

NSString的查詢字串位置擷取字串

查詢字串位置: NSRange range; range = [tmpStr rangeOfString:@"ccd"]; if (range.location != NSNotFound) { NSLog(@"found at locati

倒計時切換 開始結束

move 顯示 ont tin call () doc loop script /* * @Author: Mark * @Date: 2015-08-06 13:54:01 * @Last Modified by: Mark * @Last Modified

在一個gradle 的maven property 裏添加URL

public http let rac mod TE fab OS tps 這樣是會報錯的 repositories { mavenCentral() maven { url "http://maven.springframewo

一個Filter配置url-pattern

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

web.xml中一個filter配置url-pattern

需要在filter標籤後新增多個filter-mapping標籤,一個url-pattern就對應一個filter-mapping標籤,不能直接把多個url-pattern配置到同一個filter-mapping標籤裡,也不能直接把多個url直接配置到一個url-pattern標籤裡。 正確地配置方式如下所

爬取url頁面資料--手動實現

# -*- coding: utf-8 -*- import scrapy from qiubaiByPages.items import QiubaibypagesItem class QiubaiSpider(scrapy.Spider): name = 'qiubai'

變速動畫函數封裝增加任意屬性、透明度層級

是否 false win 定時器 flag set -c 屬性 .get //計算後的樣式屬性---- 一個元素的任意的一個樣式屬性值function getStyle(element,attr) { //判斷這個瀏覽器是否支持這個方法 return windo

vue router-view 檢視巢狀 命名router-view

多個router-view檢視巢狀: 1,除了app.vue中的router-view之外,還有其他的巢狀在router-view中的router-view檢視,子路由寫在router.js children中 app.vue <template> <div i

react native載入jsbundle(assets其他目錄)

在使用ReactInstanceManager.Builder構建一個ReactInstanceManager例項的時候只能傳入一個bundle,setBundleAssetName和setJSBundleFile分別對應從assets和從一個檔案路徑載入Bundle。有時需要將業務程式碼和通用

vue上傳檔案,附件其他資料一起傳給後臺

前端: 實現多圖上傳主要用到以下兩個屬性:        <el-form-item label="附件上傳" label-width="80px">       <el-f

CString字串查詢擷取

1、Find() 該函式從左側0索引開始,查詢第一個出現的字元位置 CString str( “abc” ); int postion=str.Find(‘a’); 如果查到,返回以0索引起始的位置;未查到,返回-1。 2、FindOneOf() 給定一字串,然

通過字元進行分割

        /// <summary>         ///通過多個字元進行分割         /// </summary>   &nbs

爬取url

# -*- coding: utf-8 -*- import scrapy from qiubai.items import QiubaiItem class QiushibaiSpider(scrapy.Spider): name = 'qiushibai' # allowed_d

if、elifelse的搭配使用

if…if…if…搭配成的語句塊,會一個個去匹配是否滿足if裡面的語句; if與elif的搭配成的語句塊,當匹配到if或者elif語句判斷為True的時候,那麼不會執行下面elif以及else裡面的語句; 示例1: a = 10 if a > 1:

攔截器中URL-PATTERN配置

有的時候做攔截器需要對多個資料夾進行攔截,在web.xml中配置如下:    <filter-mapping>         <filter-name>             testFilter         </filter-nam

ab進行url壓力測試

1.安裝ab(linux需要root許可權) 在任意目錄下執行該命令:yum -y install httpd-tools 測試一下ab是否安裝成功:ab -V 2.ab併發壓測指令碼 #!/b

UbuntuJDK版本配置切換

概述 一般Ubuntu16會自帶open jdk8,而我們需要的是sun JDK,於是就需要重新安裝sun JDK,並將系統預設JDK切換為sun JDK。 下載JDK 下載地址: 安裝JDK 將JDK安裝包解壓到指定目錄/usr/soft