我从JSON url获取图片。我试过这样但我确实没有得到图像
NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSLog(@"all NSMutable2%@",al);
NSDictionary *dict = [al objectAtIndex:1];
NSString *title=[dict objectForKey:@"dealimage"];
NSLog(@"all DIC%@",title);
NSData *data1 = [[NSData alloc] initWithData:[NSData
dataFromBase64String:title]];
NSLog(@"********************************%@",data1);
NSData* data = [Base64 decode:title ];
UIImage *image = [UIImage imageWithData:data];
dig=[[UIImageView alloc]initWithImage:image];
[self.view addSubview:dig];
dig.frame = CGRectMake(0, 25 , 150,150);
我的想法是先将NSString数据转换为NSData,然后NSData传递给UIImage.But没有运气 所以请给我任何想法
答案 0 :(得分:1)
#import "NSData+Base64.h"
//Creating the data from your base64String
NSData *data = [[NSData alloc] initWithData:[NSData dataFromBase64String: title]];
//Now data is decoded. You can convert them to UIImage
UIImage *image = [UIImage imageWithData:data];
dig=[[UIImageView alloc]initWithImage:image];
dig.frame = CGRectMake(0, 25 , 150,150);
[self.view addSubview:dig];