gpt4 book ai didi

objective-c - 显示来自 json 的图像

转载 作者:行者123 更新时间:2023-12-01 18:00:06 25 4
gpt4 key购买 nike

我无法显示从 json 文件加载的图像。
我正在使用 JSONKit 解析我的 json,一切正常,但我无法在 UIImageview 中加载图像.我希望你们中的一些人可以帮助我。

在我的代码下方,我认为可能是正确的,但事实并非如此。

UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 115)];
image.image = [UIImage imageNamed:[detailView objectForKey:@"thumbnail"]];

[self.view addSubview:image];
[image release];

最佳答案

我认为在 json 中你正在获取图像的 url。使用以下代码从 url 显示图像

 //NSURL *url = [NSURL URLWithString:@"http://192.168.1.2x0/pic/LC.jpg"];
NSURL *url = [NSURL URLWithString:[detailView objectForKey:@"thumbnail"]];

NSData *data = [NSData dataWithContentsOfURL:url];
UIImageView *subview = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,320.0f, 460.0f)];
[subview setImage:[UIImage imageWithData:data]];
[self.view addSubview:subview];
[subview release];

关于objective-c - 显示来自 json 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11224158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com