开发者

Flex binary String to ByteArray

开发者 https://www.devze.com 2023-01-10 05:33 出处:网络
On the server side, I have an array of objects. Each object has 3 integer fields and 2 binary fields.

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 b开发者_运维问答yte 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号