Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 显示来自json的图像_Objective C_Ios_Json_Uiimageview_Uiimage - Fatal编程技术网

Objective c 显示来自json的图像

Objective c 显示来自json的图像,objective-c,ios,json,uiimageview,uiimage,Objective C,Ios,Json,Uiimageview,Uiimage,我无法显示从json文件加载的图像。 我正在用JSONKit解析json,一切正常,但我无法在UIImageview中加载图像。我希望你们中的一些人能帮助我 在我的代码下面,我认为可能是正确的,但事实并非如此 UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 115)]; image.image = [UIImage imageNamed:[detailView objectForKey

我无法显示从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];

我认为在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];
你发布的代码

image.image = [UIImage imageNamed:[detailView objectForKey:@"thumbnail"]];
将尝试在包中查找名为字符串的图像,该字符串存储在[detailView objectForKey:@thumbnail]中

正如您提到的,您的映像来自远程服务器,您必须从远程服务器下载映像

 UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 115)];
 image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[detailView objectForKey:@"thumbnail"]]]];
[self.view addSubview:image];
[image release]
你发布的代码

image.image = [UIImage imageNamed:[detailView objectForKey:@"thumbnail"]];
将尝试在包中查找名为字符串的图像,该字符串存储在[detailView objectForKey:@thumbnail]中

正如您提到的,您的映像来自远程服务器,您必须从远程服务器下载映像

 UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 115)];
 image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[detailView objectForKey:@"thumbnail"]]]];
[self.view addSubview:image];
[image release]

此[detailView objectForKey:@thumbnail]包含什么内容?您的图像是否来自远程服务器?还是在你的项目中?@Janusfiel来自远程服务器。它包含如下字符串:缩略图:,此[detailView objectForKey:@thumbnail]包含什么?您的图像来自远程服务器吗?还是在你的项目中?@Janusfiel来自远程服务器。它包含一个字符串,如下所示:缩略图:,啊,非常感谢,它工作得非常好。。我有一个想法,它与NSURL有关,但我无法理解。非常感谢。啊,非常感谢。效果非常好。。我有一个想法,它与NSURL有关,但我无法理解。非常感谢你。