今天開發高德雲圖,傳回來的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~