I am implementing an interface, which specifies writeBytes() and readBytes() on a file. The data has to be transported as JSON.
For readBytes I do the following: 1. NSFileHandle readDataofLength - to read from a file 2. NSString initWithData: encoding: - to specify a given encoding 3. NSString getBytes:buffer 4. put each buffer[i] into a JSON array for transport : [116,101,115,116] for example "test" as UTF-8
On the other hand writeBytes should be doing about the same: 1. Parse the JSON array to a NSArray 2. NSArray getObjects:buffer - the conversion up to this point is successful 3. NSString initWithBytes:buffer length: encoding: - is not working, the return value is null 4. NSData dataUsingEncoding: 5. NSFileHandle writeData
Apparently NSString initWithBytes cannot handle buffers with content such as [116,101,115,116]. Is there any other way to convert a NSString into a ByteArray and back ?
Thanks