AS3使用Json 传复杂数据 -------- 用数组而不是向量

package
{
    
    public class Person
    {
        private var name:String;
        
        public function get Name():String { return name; }
        
        private var age:int;
        
        public function get Age():int { return age; }
        
        private var job:String;
        
        public function get Job():String { return job; }
        
        public function Person(_name:String,_age:int,_job:String)
        {
            name = _name;
            age = _age;
            job = _job;
        }
    }
}
package
{
    public class Company
    {
        public function get Name():String { return name; }
        private var name:String;
        public function get EstablishmentDate():int { return establishmentDate; }
        private var establishmentDate:int;
        public function get EmployeeNum():int { return employees.length; }
        private var employeeNum:int;
        public function get Employees():Array{ return employees; }
        private var employees:Array;
        public function Company(_name:String,_establishment:int)
        {
            name = _name;
            establishmentDate = _establishment;
            employees = new Array();
        }
        
        public function AddEmployee(_name:String, _age:int, _job:String):Person {
            var p:Person = new Person(_name, _age, _job);
            employees.push(p);
            return p;
        }
    }
}

准备传一个公司的数据,公司里有雇员。

var company:Company = new Company("HelloCompany", 2013);
            company.AddEmployee("John", 22, "AJob");
            company.AddEmployee("Bob", 32, "BJob");
            company.AddEmployee("Mark", 20, "ADJob");
            company.AddEmployee("May", 42, "ACJob");
            
            var c:Object = JSON.encode(company);


注意一点,如果雇员用向量存储,就会出错。

posted @ 2013-08-09 12:07  向恺然  阅读(476)  评论(0编辑  收藏  举报

我必须说的是:我崇尚开源,但鄙视剽窃。本博客所有引用的图片,文章,和代码,均只作为研究学习使用,不作为商业应用。如果我无意中冒犯了您,请发消息留言,我将立即删除。