Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:37:27+00:00 2026-06-13T12:37:27+00:00

I try to get an image in JSON , but how can I get

  • 0

I try to get an image in JSON, but how can I get the image into a NSData?
All I get is an __NSCFArray with my binary data, but how to convert it?

EDIT:
This is my result in json

Printing description of resDict:
{
Details = "Foo";
GroupingInfo = LRU;
HeaderLeft = "Bar";
HeaderRight = "Foo";
Id = "cb217aeb-14e3-4bd5-8895-3217238deb2c";
IsGray = 0;
AnotherId = "<null>";
MainImage =     (
    137,
    80,
    78,
    71,
 ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:37:28+00:00Added an answer on June 13, 2026 at 12:37 pm

    You first have to parse the JSON, then take the binary part, into NSData. UIImage has a method to do change NSData into image

    UIImage *myimage = [UIImage imageWithData:mydata];
    

    Update : (hope no one minds)
    After making myself such a demo, NSJSONSerialization always returns strings, and after having a small back and forth conversation below. I tried to send an image as a Base64 coded string and read back in as data using base64 decode. This works as a charm.

    This is the code I use (since this works on all iOS versions, from 3.0 and up) :

    NSData+PHBase64.h

    @interface NSData (PHBase64)
    
    + (id)dataWithBase64EncodedString:(NSString *)string;     //  Padding '=' characters are optional. Whitespace is ignored.
    - (NSString *)base64Encoding;
    @end
    

    NSData+PHBase64.m

    #import "NSData+Base64.h"
    
    
    static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    
    
    @implementation NSData (PHBase64)
    
    + (id)dataWithBase64EncodedString:(NSString *)string;
    {
        if (string == nil)
            [NSException raise:NSInvalidArgumentException format:nil];
        if ([string length] == 0)
            return [NSData data];
    
        static char *decodingTable = NULL;
        if (decodingTable == NULL)
        {
            decodingTable = malloc(256);
            if (decodingTable == NULL)
                return nil;
            memset(decodingTable, CHAR_MAX, 256);
            NSUInteger i;
            for (i = 0; i < 64; i++)
                decodingTable[(short)encodingTable[i]] = i;
        }
    
        const char *characters = [string cStringUsingEncoding:NSASCIIStringEncoding];
        if (characters == NULL)     //  Not an ASCII string!
            return nil;
        char *bytes = malloc((([string length] + 3) / 4) * 3);
        if (bytes == NULL)
            return nil;
        NSUInteger length = 0;
    
        NSUInteger i = 0;
        while (YES)
        {
            char buffer[4];
            short bufferLength;
            for (bufferLength = 0; bufferLength < 4; i++)
            {
                if (characters[i] == '\0')
                    break;
                if (isspace(characters[i]) || characters[i] == '=')
                    continue;
                buffer[bufferLength] = decodingTable[(short)characters[i]];
                if (buffer[bufferLength++] == CHAR_MAX)      //  Illegal character!
                {
                    free(bytes);
                    return nil;
                }
            }
    
            if (bufferLength == 0)
                break;
            if (bufferLength == 1)      //  At least two characters are needed to produce one byte!
            {
                free(bytes);
                return nil;
            }
    
            //  Decode the characters in the buffer to bytes.
            bytes[length++] = (buffer[0] << 2) | (buffer[1] >> 4);
            if (bufferLength > 2)
                bytes[length++] = (buffer[1] << 4) | (buffer[2] >> 2);
            if (bufferLength > 3)
                bytes[length++] = (buffer[2] << 6) | buffer[3];
        }
    
        realloc(bytes, length);
        return [NSData dataWithBytesNoCopy:bytes length:length];
    }
    
    - (NSString *)base64Encoding;
    {
        if ([self length] == 0)
            return @"";
    
      char *characters = malloc((([self length] + 2) / 3) * 4);
        if (characters == NULL)
            return nil;
        NSUInteger length = 0;
    
        NSUInteger i = 0;
        while (i < [self length])
        {
            char buffer[3] = {0,0,0};
            short bufferLength = 0;
            while (bufferLength < 3 && i < [self length])
                buffer[bufferLength++] = ((char *)[self bytes])[i++];
    
            //  Encode the bytes in the buffer to four characters, including padding "=" characters if necessary.
            characters[length++] = encodingTable[(buffer[0] & 0xFC) >> 2];
            characters[length++] = encodingTable[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)];
            if (bufferLength > 1)
                characters[length++] = encodingTable[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)];
            else characters[length++] = '=';
            if (bufferLength > 2)
                characters[length++] = encodingTable[buffer[2] & 0x3F];
            else characters[length++] = '=';    
        }
    
        return [[NSString alloc] initWithBytesNoCopy:characters length:length encoding:NSASCIIStringEncoding freeWhenDone:YES];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when i try to upload an image: OSError at /upload/
I am try to get the image from this url. http://open.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-1,51.466407,-0.952418,0,0%7Cpurple-2,51.466102,-0.958293,0,0%7C&center=51.466252499999996,-0.9553555&zoom=12&key=Kmjtd%7Cluu7n162n1%2C22%3Do5-h61wh&rand=2031817700&session=4eeb5481-00f2-0000-02b7-64f1-002655800398 I can successfully
I need fast to get the image from a game. And i try with
i try to get my FragmentPagerAdapter working, but the examples are a bit to
I try to get all WPF window controls collections. In other words i try
I try to get the name of executable name of all of my launched
I've made gridview application that get image path from JSON. my gridview had store
I've made gridview application that get path of image from json. it work find
I'm trying to get this resolve for days but no luck yet. Please help
I try to use Twitter Get users/lookup to look up users information. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.