Iphone 如何从web服务JSON获取图像?
如何从json webservice响应获取图像并在iphone中显示。因为我得到了很好的回应 这是我的web服务响应的一部分:Iphone 如何从web服务JSON获取图像?,iphone,Iphone,如何从json webservice响应获取图像并在iphone中显示。因为我得到了很好的回应 这是我的web服务响应的一部分: { "Campaign Id" = 215; "Campaign Name" = "Denivit 2in1 Extreme White"; "Final Report Link" = "https://www.buzzador.com/report2/index.php?sid=29282&token=173
{
"Campaign Id" = 215;
"Campaign Name" = "Denivit 2in1 Extreme White";
"Final Report Link" = "https://www.buzzador.com/report2/index.php?sid=29282&token=1731692044";
"Flash Report Count" = 1;
"Last Date Registration" = "2008-05-18";
"Link for checking delivery status" = "";
"Product image" = "denivit.jpg";
Status = reported;
},
在哪个产品图像中包含图像url…现在如何在iPhone中打印此图像?您必须使用
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:yourImageURLString]];
UIImage *image = [UIImage imageWithData:imageData];
现在,您可以使用将图像
指定给UIImageView
对象。由于这是一个阻塞操作,您应该在后台线程中启动它,并将UI更新发送回主线程
如果您对解析JSON
文件感兴趣,那么有一些很好的库,其中之一就是
NSURL *url = [NSURL URLWithString:@"yourimage"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];