How to parse JSON in AS3

时间:2016-07-11 19:04:48

标签: actionscript-3 flash

I'm trying to build an application in Flash, but I have a problem. I'd like to parse the JSON from an web URL.

link: JSON text to parse

I'd like to get the JSON string "title" from here. Is there a way I can do it?

It says undefined.

var VidDataLoader = new URLLoader();

var VidUrl = "THEURL" + param1.getString(0);

trace(VidUrl)

 VidDataLoader.load( new URLRequest(VidUrl))

VidDataLoader.addEventListener(Event.COMPLETE, doneit)

function doneit(e:Event){ var myData:Object = JSON.parse(VidDataLoader.data);

1 个答案:

答案 0 :(得分:0)

您正尝试从VidDataLoader类访问数据,但加载的数据是事件对象的一部分:

public function JSONLoader() {
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, decodeJSON);
    loader.load(new URLRequest("myfile.json"));
}

// use the event to get the data
private function decodeJSON(e:Event):void {
    var loader:URLLoader = URLLoader(e.target) ;
    var jsonObject:Object = JSON.parse(loader.data);
}