我按如下方式迭代NSDictionary,如果它包含字符串htttp,则将值分配给字符串。
for(id key in photos){
//NSLog(@"key=%@ value=%@", key, [photos objectForKey:key]);
if ([[[photos objectForKey:key] stringByAppendingString: key] containsString:@"http"]){
photoUrl = [[photos objectForKey:key] stringByAppendingString: key];
}
NSLog(@"etf %@",photoUrl);
}
答案 0 :(得分:1)
如果您从某个阵列获得
NSString *joinedComponents = [array componentsJoinedByString:@","]
;
否则你可以遍历一些自己的集合
NSMutableString * string1 = [[NSMutableString alloc] initWithString:@"this is my string"];
[string1 appendString:@" with more strings attached"];
同样,你可以稍后将它们分开
NSArray *items = [string1 componentsSeparatedByString:@","];
将键值保存在字符串中并制作您的网址。
答案 1 :(得分:1)
在循环中创建一个数组,
NSArray *urls = [NSMutableArray array];
for (id key in photos) {
NSString *photoUrl = [[photos[key] stringByAppendingString: key]
if (photoUrl containsString:@"http"]){
urls appendItem[photoUrl];
}
}
然后您可以使用
创建CSV字符串NSString *csvUrls = [urls componentsJoinedByString:@","];
并用
将其分解NSArray *urls = [csvUrls componentsSeparatedByString:@","];