Problem with converting byte array to iphone

I have a little dilemma with the iphone project.

I get some JSON data from a web service. I can deserialize it in the OK dictionary. One of the dictionary values ​​is a binary file (image), but my JSON library deserializes it as an NSArray from NSDecimalNumbers!

How to convert this NSArray from NSDecimalNumbers to an NSData object so that I can successfully generate an image from it using [UIImage imageWithData: myNSData]?

+3
source share
1 answer

How about this

unsigned char *buffer = (unsigned char*)malloc([arrayOfNumbers count]);
int i=0;
for (NSDecimalNumber *num in arrayOfNumbers) {
    buffer[i++] = [num intValue];
}
NSData *data = [NSData dataWithBytes:buffer length:[arrayOfNumbers count]];
free(buffer);

... or something similar depending on the ranges of NSDecimalNumbers.

+3
source

Source: https://habr.com/ru/post/1714705/


All Articles