1

I'm trying to download a file in Objective-C from a REST service but having some issues. Right now, the service returns a byte[] in JSON. I was able to get the array by using the json-framework.

NSURL *url = [NSURL URLWithString:@"http://192.168.10.215:8888/Service/RO/GetAllTheBytes/test.txt"];
NSString *str = [[NSString alloc] initWithContentsOfURL:url];
NSDictionary *jsonDic = [str JSONValue];
NSArray *fileContents = [jsonDic objectForKey:@"fileContents"];

Now I want to use this array of bytes to create a file, but I'm having trouble creating the file. Should I convert the NSArray to NSData, and how?

gcamp
  • 14,622
  • 4
  • 54
  • 85

1 Answers1

1

Change your service to return a Base64 string. There are a bunch of Objective-C Base64 decoders out there, some of which are half-decent.

A NSArray of NSNumbers is really really really stupid, with a minimum space overhead of about 300% (although not quite as bad as JRA-11693).

tc.
  • 33,468
  • 5
  • 78
  • 96