I’m using a URLLoader and URLRequest to make a call to youtube’s api. The return is formatted as json and looks like the following: http://pastebin.com/WxPS9NCB.
I’m trying to capture the “href” value located on line 42 in the above pastebin. But the code I have isn’t working.
var urlLoader:URLLoader = new URLLoader(new URLRequest(apiURL));
urlLoader.addEventListener(Event.COMPLETE, function(e:Event) {
var json:Object = e.target.data;
var href:String = json.link[0].href;
trace(href);
});
Any ideas?
Flash does not parse JSON automatically. Use AS3 core libs JSON parser (https://github.com/mikechambers/as3corelib)
And replace
var json:Object = e.target.data;withvar json:Object = JSON.decode(e.target.data);EDIT:
After a cursory glance at the JSON file you should use
json.feed.link[0].hrefto access the data you are looking for.