AS3的iOS:如何序列化数组,然后将其保存 [英] AS3 for ios : how to serialize an array and then save it

查看:303
本文介绍了AS3的iOS:如何序列化数组,然后将其保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多维数组,我想序列化,然后使用共享对象保存。 我试过很多东西,但每次出现了问题。

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:结果不是字符串,则共享对象不希望保存

ByteArray : the result is not a String, then the SharedObject doesn't want to save it.

可能是共享对象不是解决方案的一部分。

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;
    }
}

我能做到这一点:

I could do this:

registerClassAlias("com.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的iOS:如何序列化数组,然后将其保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆