0

我试图编写一个类,它将返回给定字符串的 json 对象。我知道下面代码的语法是完全错误的,但只是尝试这样做。

package com 
{
    import flash.display.MovieClip;
    import com.adobe.*;
    import com.adobe.serialization.json.JSON;
    import flash.net.dns.AAAARecord;
    import flash.net.URLRequest;
    import flash.events.Event;

    public class getJson extends MovieClip
    {

        public function getJson(urlString:String):Object
        {
            // constructor code
            var returnObject:Object = new Object();
            var urlLoader:URLLoader = new URLLoader();
            returnObject=urlLoader.addEventListener(Event.COMPLETE,loadingComplete);
            urlLoader.load(new URLRequest(urlString));
            return returnObject;


        }

        private function loadingcomplete(e:Event):Object
        {
            var jsonObject:Object = new Object();
            jsonObject=JSON.decode(urlString);
            return jsonObject;
        }

    }

}
4

1 回答 1

-1

尝试这个:

  public var urlLoader:URLLoader;
  public  String url;
   public function getJson(urlString:String):Object
    {
        url=urlString;            
        var returnObject:Object = new Object();
        urlLoader = new URLLoader();
        urlLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);
        urlLoader.load(new URLRequest(urlString));
        returnObject=urlLoader.addEventListener(Event.COMPLETE,onComplete);            
        return returnObject;

    }
   function onProgress(e:ProgressEvent):void
  {
    trace("Progressing");
  }
   function onComplete(e:Event):void
  {
    trace("Fully loaded");      
    urlLoader.removeEventListener(ProgressEvent.PROGRESS, onProgress);
    urlLoader.removeEventListener(Event.COMPLETE, onComplete);
    var jsonObject:Object = new Object();
    jsonObject=JSON.decode(url);
    return jsonObject
  }
于 2013-10-15T10:18:02.450 回答