-4

I am trying to get the image from the byte array. I can only get the image if enter the byte array values into the string directly as follows:

    NSMutableString *imagen = [[NSMutableString alloc] initWithString:@"-1,-40,-1,-32,0,16,74,70,73,70,0,1,0,1,0,96,0,96,0,0,-1,-2,0,31,76,69,65,68,32,84,101,99,104,110,111,108,111,103,105,101,115,32,73,110,99,46,32,86,49,46,48,49,0,-1,-37,0,-124,0,5,5,5,8,5,8,12,7,7,12,12,9,9,9,12,13,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13];

//this way works fine

IF i try to get the byte array into string as follows,then I couldnt get the image:

    NSString *logo=[NSString stringWithFormat:@"%@",[[JSON valueForKey:@"request"]valueForKey:@"logo" ]];

    NSMutableString *imagen = [[NSMutableString alloc] initWithString:logo];

   //this way doesnt work out

I am following this link to get the thing done.this link

Could you please tell me whats the proper way to get byte array from JSON?

Community
  • 1
  • 1
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • 1
    How is the image data encoded in the JSON since JSON does not support data? Base64 or something else? – zaph Feb 09 '15 at 22:31
  • I ddidnt encoded the image. It is done by another developer. I am updating my question. PLease look into it. – Teja Nandamuri Feb 09 '15 at 22:33

2 Answers2

2

This is not executable code, it is a method to use:

You get the JSON in self.receivedData

Convert it into an object with
NSDictionary *jsonObject = NSJSONSerialization JSONObjectWithData:

** Unknown how the image data is encoded in the JSON. If it is Base64 encoded:

Get the Base64image string with
NSString *imageString = jsonObject[@"request"][@"logo"]

Convert the Base64 string into data:
NSData *imageData = [NSData alloc] initWithBase64EncodedString: imageString options:

Get an image with
UIImage *logoImage = [imageData imageWithData]

All in all you have way to much code that accomplished nothing and converting the image data to an NSString is incorrect.

Converting to a string and then back to data accomplishes nothing.

zaph
  • 111,848
  • 21
  • 189
  • 228
0

This code seems confused? The link you posted has string encodings which contain negative numbers. You parse these as signed but then assign them to an array of unsigned uint8_t using bytes[i] = (uint8_t)byte;.

I think you need to post the string encoding format and an example?

Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28