TestVo【Vector、JSON(as3corelib-.92.1 Abode官方类库)】

package

{

    import flash.utils.describeType;



    public class TestVo

    {

        public function TestVo()

        {

        }

        public var expe:int;

        public var gCoin:Number;

        public var expeId:int;

        public var star:Number;

        public var teamId:int;

        public var descr:String;

        public var ring:int;

        public var orcStr:*;

        public var mon:*;

        

        public var good:*;

        

        public function toString():String

        {

            var xml:XML = describeType(this);

            var str:String = '...TestVo ...\n';

            for (var i:int=0; i<xml.child('variable').length(); i++)

            {

                var vName:String = '' + xml.child('variable')[i].attribute('name');

                str +=  '...*' + vName + ' : ' + this[vName] + '\n';

            }

            str +=  '... TestVo ...\n';

            return str;

        }



    }

}
package 

{

    import flash.display.Sprite;

    import flash.utils.describeType;

    import flash.utils.getQualifiedClassName;



    import com.adobe.serialization.json.JSON;



    public class Test1 extends Sprite

    {

        public function Test1()

        {

            var vo:TestVo = new TestVo();

            var str:String = '{"expeId":1,"star":2,"teamId":3,"descr":4,"ring":5,"orcStr":6,"expe":7,"mon":8,"gCoin":9}';

            var obj:Object = JSON.decode(str);



            var xml:XML = describeType(vo);

            trace("..xml..start..\n"+xml+"\n....xml..end...");



            for (var i:int=0; i<xml.child('variable').length(); i++)

            {

                var vName:String = '' + xml.child('variable')[i].attribute('name');

                

                trace("obj.hasOwnProperty(vName)  : "+obj.hasOwnProperty(vName));

                

                if (obj.hasOwnProperty(vName) == false)

                {

                    trace("continue...vName  :  "+vName);

                    continue;

                }

                if (getQualifiedClassName(vo[vName])=='String')

                {

                    vo[vName] = '' + obj[vName];

                }

                else if (getQualifiedClassName(vo[vName])=='Number')

                {

                    vo[vName] = Number(obj[vName]);

                }

                else if (getQualifiedClassName(vo[vName])=='int')

                {

                    vo[vName] = Math.round(int(obj[vName]));

                }

                else

                {

                    vo[vName] = obj[vName];

                }

                trace("vo["+vName+"]***"+vo[vName]);

            }

            trace(vo.toString());

        }

    }

}

 

你可能感兴趣的:(vector)