我的密码就像..。
NSString *str=[arrInitiatives valueForKey:@"FileName"];
NSLog(@"file name ----> %@",str);
NSString *imageUrl = [NSString stringWithFormat:@"%@%@", PUBLIC_UTILITY_FORMS_URL,str];
NSLog(@"----> %@",imageUrl);
[_image_imageview setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"noimage.png"]];
//http://setupolice.org/brcsetu/UploadFile/Lighthouse4908.jpg从这段代码中,我会得到
file name ----> (
"Lighthouse4908.jpg"
)
----> http://setupolice.org/brcsetu/UploadFile/(
"Lighthouse4908.jpg"
)
I want this
----> http://setupolice.org/brcsetu/UploadFile/Lighthouse4908.jpg发布于 2016-06-23 08:20:54
尝尝这个
NSString *str=[[arrInitiatives valueForKey:@"FileName"] objectAtIndex:0];致以敬意,
阿米特
发布于 2016-06-23 08:31:43
当使用代码创建str变量时
NSString *str=[arrInitiatives valueForKey:@"FileName"];实际上,它不返回NSString对象,而是返回NSArray对象。这就是为什么文件名在日志中的括号内:
file name ----> (
"Lighthouse4908.jpg"
)如果您确信文件名将始终存在于数组中,则可以尝试@在其答复中建议的内容。
问题是,当这个数组为空时,您将在执行此代码时得到一个错误。我宁愿这样做:
NSArray *filenames = [arrInitiatives valueForKey:@"FileName"];
NSString *str = nil;
if (filenames.count) {
str =[arrInitiatives valueForKey:@"FileName"];
}
NSLog(@"file name ----> %@",str);当然,在创建imageUrl之前,您必须检查str是否为零。
https://stackoverflow.com/questions/37985766
复制相似问题