目标是通过将 sqlbinary 作为 JSON 发送到 iphone 的 Web 服务拉取存储为 sql server 中的 varbinary 的图像。我无法从 JSON 发送的 base64binary 设置 UIImage。我能够将二进制文件转换为 NSData 但图像不是通过数据设置的。
for (int i = 0; i < array.count; i++) {
NSDictionary *mealInfo = [array objectAtIndex:i];
Meal *meal =[[Meal alloc]initWithRestaurant:[mealInfo objectForKey:@"restaurantname"]
mealName:[mealInfo objectForKey:@"itemname"]
description:[mealInfo objectForKey:@"itemdescription"]
Time:[mealInfo objectForKey:@"mealTime"]
price:[mealInfo objectForKey:@"itemprice"]];
//NSString *str = @"data:image/jpg;base64,";
//str = [str stringByAppendingString:[mealInfo objectForKey:@"itemImage"]];
//NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];
NSString *str = [mealInfo objectForKey:@"itemImage"];
NSLog(@"%@", str);
NSData *d = [[NSData alloc]initWithData:[NSData dataFromBase64String:str]];
UIImage *image = [UIImage imageWithData:d];
[meal setMealImage:image];
[meals addObject:meal];
}
NSLog(@"%@",[[meals objectAtIndex:0]mealPrice]);
NSLog(@"This is how many meals %d", meals.count);