AS3 JSON.stringify错误#1129:循环结构无法转换为JSON字符串

时间:2014-04-21 16:25:47

标签: json actionscript-3 stringify

把头发拉过这个。

在VO数组(值对象)上调用stringify会引发以下错误

Error #1129: Cyclic structure cannot be converted to JSON string.

它可能与我的VO中的getter,setter有关吗?还有其他事情发生,因为我可以使用一堆空的VO初始化一个数组,并将它们串联起来没问题。

任何帮助表示赞赏!

这是我完整的价值对象

package app.model.vo
{

    import app.model.events.*;


    import flash.display.*;
    import flash.display.Loader;
    import flash.events.ErrorEvent;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IOErrorEvent;
    import flash.filesystem.File;
    import flash.net.*;

    public class VO extends EventDispatcher
    {
        private var _name:String;
        private var _url:String;
        private var _bitmap:Bitmap;
        private var _bitmapData:BitmapData;

        private var _filter:RegExp=/^\S+\.(jpg|jpeg|png)$/i;



        private var _loader:Loader;


        private var _appDir:File = File.applicationDirectory;
        private var _imgFile:File;

        private var _wins:int=0;
        private var _losses:int=0;
        private var _ties:int=0;

        private var _gamesPlayed:int=0;

        private var _timeStamp:int=0;

        private var _id:String='';
        private var _id2:String='';

        public function VO(sName:String='', sUrl:String='', bmd:BitmapData=null,id:String='',id2:String='')
        {
            _name=sName;
            _url=sUrl;
            _bitmapData=bmd;
            _id=id;
            _id2=id2;

            _loader=new Loader();
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete,false,0,true);
            _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError,false,0,true);

            _imgFile = _appDir.resolvePath('imgs/'+ sUrl);

            if( _imgFile!=null){
                if (validateFile(_imgFile))
                {
                    _loader.load(new URLRequest(_imgFile.url));
                }
                else
                {
                    dispatchEvent(new Event('invalid'));
                }
            }
        }

        public function clean():void
        {

            if (_thumbnail != null)
                _thumbnail.dispose();
            if (_bitmapData != null)
                _bitmapData.dispose();

        }

        public function clone():AttendeeVO
        {
            return new AttendeeVO(_name, _url, _bitmapData.clone());
        }

        public function get fileExtension():String
        {
            return _name.substr(_name.lastIndexOf('.'), _name.length).toLowerCase();
        }

        public function set name(str:String):void
        {
            _name=str;
        }

        public function get name():String
        {
            return _name;
        }

        public function get id():String
        {
            return _id;
        }

        public function get id2():String
        {
            return _id2;
        }

        public function set url(str:String):void
        {
            _url=str;
        }

        public function get url():String
        {

            return _url;
        }


        public function win():void
        {
            _wins=int(_wins+1);

        }

        public function get wins():int
        {
            return _wins;

        }

        public function lose():void
        {

            _losses=int(_losses+1);
        }

        public function get losses():int
        {
            return _losses;

        }

        public function tie():void
        {

            _ties=int(_ties+1);
        }


        public function get ties():int
        {
            return _ties;

        }

        public function get gamesPlayed():int
        {
            _gamesPlayed= int(_wins + _losses+_ties);
            return _gamesPlayed;
        }


        public function get score():int
        {
            var s:int;
            if(gamesPlayed>0){
                s=int(_wins-_losses);
            }else{
                s = -999;
            }
            return s;
        }

        public function get timeStamp():int
        {

            return _timeStamp;
        }


        public function set timeStamp(val:int):void
        {
            _timeStamp=val;
        }

        public function set bitmap(bm:Bitmap):void
        {
            _bitmap=bm;
        }

        public function get bitmap():Bitmap
        {
            return _bitmap;
        }

        public function set bitmapData(bmp:BitmapData):void
        {
            _bitmapData=bmp;
        }

        public function get bitmapData():BitmapData
        {
            return _bitmapData;
        }

        public function set thumbnail(bmp:BitmapData):void
        {
            _thumbnail=bmp;
        }

        public function get thumbnail():BitmapData
        {
            return _thumbnail;
        }

        private function onLoadComplete(e:Event):void
        {

            _bitmap=_loader.content as Bitmap;
            dispatchEvent(new ImageLoadEvent(ImageLoadEvent.LOAD, _imgFile, _bitmap,_name));
            _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
            _loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
            _loader=null;

        }

        private function onLoadError(evt:IOErrorEvent):void
        {
            dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, evt.text));
        }

        private function validateFile(file:File):Boolean
        {
            if(_filter.exec(file.name) != null){
                return true
            }else{
                return false;
            }
        }
    }
}

0 个答案:

没有答案