简体   繁体   English

如何将Byte数据类型的json转换为UIImage

[英]How to convert json with data type of Byte to UIImage

I am seeking for a help on how to convert a json value with data type of byte into an image. 我正在寻求有关如何将字节数据类型的json值转换为图像的帮助。 I don't have any idea of this. 我对此一无所知。

Try this, I am assuming you have base-64 encoded form of image 试试这个,我假设您使用的是base-64编码形式的图像

NSData *imageData = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters];

UIImage *image = [UIImage imageWithData: imageData];

There is no data type of "byte" in JSON. JSON中没有“字节”的数据类型。 The data types are array, dictionary, string, number, bool and null. 数据类型为数组,字典,字符串,数字,布尔值和null。 You might be getting a string with a base-64 encoded image. 您可能会得到一个字符串,其中包含以base-64编码的图像。 (You might get an array of numbers if the website developer is mad enough) Decode it to get an NSData object, pass that to the right UIImage initialiser. (如果网站开发人员非常生气,您可能会得到一个数字数组)对其进行解码以获取NSData对象,然后将其传递给正确的UIImage初始化程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM