[英]how to get images from web service JSON?
如何从 json 网络服务响应获取图像并在 iphone 中显示。 因为我得到了很好的回应。
这是我的 web 服务响应的一部分:
{
"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];
现在您可以使用将image
分配给UIImageView
object。 由于这是一个阻塞操作,您应该在后台线程中启动它并将 UI 更新发送回主线程。
如果您对解析JSON
文件感兴趣,那里有一些很好的库,其中之一是TouchJSON
。
NSURL *url = [NSURL URLWithString:@"yourimage"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.