【发布时间】:2016-06-01 13:33:52
【问题描述】:
来自 JSON 文件的数据。
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSString *cPhoto = [[jsonArray objectAtIndex:i] objectForKey:@"photo"];
NSURL *urlOne = [NSURL URLWithString:cPhoto];
NSData *photoData =[NSData dataWithContentsOfURL:urlOne];
UIImage *imageOne = [[UIImage alloc] initWithData:photoData];
NSLog(@"%@",imageOne);
NSLog 视图:
[10872:310156] (null)
[10872:310156] <UIImage: 0x7f97f25cd220>, {1005, 651}
[10872:310156] <UIImage: 0x7f97f25d59c0>, {1005, 651}
[10872:310156] (null)
[10872:310156] (null)
为什么 NSLog 不显示 *.jpg 格式? .仅 *.png 文件(2-nd 和 3-rd)。 非常感谢。原谅我的英语不好!
【问题讨论】:
-
photoData是否有效是导致问题的原因?网址有效吗? -
@Larme 当然可以。除了照片获取数据类型编号、姓名、姓氏...
-
我的意思是,当
UIImage为 nil 时,photoData也为 null 吗? -
@Larme 是的。 UIImage 仅显示照片 .png 格式
-
如果
NSData为空,那么来自NSData对象的UIImage也为空是正常的。 jpg 的photoData是否获得正确的文件开头:en.wikipedia.org/wiki/JPEG#Syntax_and_structure?
标签: objective-c json string uiimageview nslog