views:

86

answers:

1

On the server side, I have an array of objects. Each object has 3 integer fields and 2 binary fields. I've utf encoded the binary data and json encoded the array & sent it to Flex client side.

On the client side, decoding data, I've got a String representing the binary data (utf decoded).

Now, how can I convert this String to ByteArray? Or how can I read each byte of the String?

A: 

Well I found the answer somehow!

It's not a good solution to utf encode the binary data. The best way seems to be Base64 encoding. Then use a Base64 decode in the flex which returns a ByteArray. Peace of a cake! Base64_encode adds approximately 33% overhead which is a bit more than utf8_encode but much easier to work with.

php:

echo json_encode (base64_encode ($data));

flex:

//use a serialization filter for your HTTPService to deocde JSON
var raw:ByteArray = new ByteArray();
var dec:Base64Decoder = new Base64Decoder();
dec.decode(data);
raw = dec.toByteArray();
Babak