Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Ios 如何从json解析图像URL_Ios_Objective C_Json_Parsing - Fatal编程技术网

Ios 如何从json解析图像URL

Ios 如何从json解析图像URL,ios,objective-c,json,parsing,Ios,Objective C,Json,Parsing,这是我的json数据,我可以获取文本类型的数据,但无法从weatherIconUrl数组获取图像url 并将此字符串转换为URL NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"]; 您还可以通过以下方式从该URL获取图像: NSURL *myURL = [NSURL URLWithString:[imgURLSt

这是我的json数据,我可以获取文本类型的数据,但无法从weatherIconUrl数组获取图像url

并将此字符串转换为URL

NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"];
您还可以通过以下方式从该URL获取图像:

NSURL *myURL = [NSURL URLWithString:[imgURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
很容易,

UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]];

你的问题有点让人困惑。你是在问如何从JSON中获取url还是如何从url中获取图像?你想从JSON url中显示图像是的,我想显示图像
UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]];
 NSError *jsonParsingError = nil;

 NSArray *weatherArray = [NSJSONSerialization JSONObjectWithData:yourResponseData options:0 error:&jsonParsingError];

 NSLog(@"weatherArray : %@", weatherArray);

 NSString *weatherIconImageURL = [[weatherArray objectAtIndex:0] objectForKey:@"weatherIconUrl"]];

 NSLog(@"weatherIconImageURL : %@", weatherIconImageURL);