简体   繁体   中英

Flex binary String to ByteArray

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM