AS3 for ios:如何序列化数组然后保存它 [英] AS3 for ios : how to serialize an array and then save it
问题描述
我有一个多维数组,我想对其进行序列化,然后使用 SharedObjects 保存它.我尝试了很多东西,但每次都出现问题.
I have an multidimentional array and I want to serialize it and then save it using SharedObjects. I tried many things, but each time there is a problem.
JSON : 不能有类型.
JSON : can't have types with it.
ByteArray : 结果不是字符串,则 SharedObject 不想保存它.
ByteArray : the result is not a String, then the SharedObject doesn't want to save it.
可能 SharedObjects 不是解决方案的一部分.
May be SharedObjects are not part of the solution.
所以我的问题是:是否有一个简单的解决方案可以将数组保存在磁盘上并检索该数组?
So my question : is there a simple solution to save an array on disc and to retrieve this array ?
谢谢.
推荐答案
需要使用flash.net.registerClassAlias
.
如果我有一堂这样的课:
So if I had a class like this:
package com {
public class Bob {
public var myArray:Array;
}
}
我可以这样做:
registerClassAlias("com.Bob", Bob);
然后您可以将 Bob 类对象保存到您的共享对象中(或者再次检索它们)
Then you can save Bob class objects into your shared objects (or rather retrieve them again)
完整示例:
//register the class - you only need to do this once in your class
registerClassAlias("com.Bob", Bob);
<小时>
//Lets save a Bob instance into a shared object
var bob:Bob = new Bob();
bob.myArray = ["blah","blah","blah"];
var bobSO:SharedObject = SharedObject.getLocal("Bob");
bobSO.data.bob = new Bob();
bobSO.flush();
<小时>
//now at a later time, let's retrieve it
var bobInstance:Bob;
var bobSO:SharedObject = SharedObject.getLocal("Bob");
if (bobSO.size > 0 && bobSO.data.bob && bobSO.data.bob != undefined) {
bobInstance = bobSO.data.bob;
}
请记住,您需要注册所有使用的类(如果您的数组中存储了不同的类).
Keep in mind, that you'll need to register ALL classes that are used (if you have different classes stored in your array).
这篇关于AS3 for ios:如何序列化数组然后保存它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!