NSString的多个URL字符串的分割和截取技巧

今天开发高德云图,返回来的image是字符串组,不是Json,也不是字典,我的妈啊!你说的是真的!


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~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值