Flash/Flex:是否可以使用 AMF 对字典进行编码?
正如标题所示,是否可以使用 AMF 来编码/解码字典(即无需子类化)?
例如,这是一个测试用例:
function serializeAndReload(obj:*):* {
var serialized:ByteArray = new ByteArray();
serialized.writeObject(obj);
serialized.position = 0;
return serialized.readObject();
}
function test():void {
var d:Dictionary = new Dictionary();
d[{}] = 42;
d[d] = true;
var x:* = serializeAndReload(d); // <<< x is an instance of Object
trace(x['[object Object]']); // <<< traces '42'
}
As the title suggests, is it possible to use AMF to encode/decode Dictionaries (without subclassing, that is)?
For example, here's a test case:
function serializeAndReload(obj:*):* {
var serialized:ByteArray = new ByteArray();
serialized.writeObject(obj);
serialized.position = 0;
return serialized.readObject();
}
function test():void {
var d:Dictionary = new Dictionary();
d[{}] = 42;
d[d] = true;
var x:* = serializeAndReload(d); // <<< x is an instance of Object
trace(x['[object Object]']); // <<< traces '42'
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可能想太多了。我使用对象而不是字典,它是使用 AMF 自动编码的。我一直使用 pyamf 来传递对象/字典,并且它总是可以工作,不需要我任何脑力劳动。我从来不需要手动序列化/反序列化任何东西
You may be over-thinking. I use Object instead of Dictionary and it is automatically encoded using AMF. I use pyamf all the time to pass Objects/dicts around and its always worked without any mental effort on my part. Never have I needed to manually serialize/deserialize anything
Dictionary
中的键也需要可序列化。测试:
输出:
The keys in the
Dictionary
need to be serializable, too.Test:
Output: