0
votes

I was wondering if someone could explain or point me in the direction of how to implement an API that uses JSON in ActionScript 3.0. What I specifically want to know is how would I grab specific information. The following is how I do it in XML but I don't know how I would do something similar in JSON as in getting the equivalent of an XML tag. For example with the twitter API I'd like to grab the text https://dev.twitter.com/docs/api/1/get/search

        -----------XML Example:
        //create a new XML object with the XML
        xml = new XML(e.target.data);

        //This gives us an XMLList (an array) of <item> tags
        var all_items:XMLList = xml.channel.item;

        //loop through the <item> tags
        for (var i:uint = 0; i < all_items.length(); i++)
        {
            //get contents of title tag
            var titleText:String = all_items[i].title.text();

            //get contents of description tag
            var descriptionText:String = all_items[i].description.text();

            //get contents of link tag
            var linkText:String = all_items[i].link.text();

            //get contents of pubDate tag
            var dateText:String = all_items[i].pubDate.text();
        }

-------NEW CODE-----

public function onJSONLoaded(e:Event) {

trace("onJSONLoaded() called");

        json = JSON.decode(e.target.data);

        trace("json=" + json);
    } 

and the trace for it is

onJSONLoaded() called

json=[object Object]

1

1 Answers

5
votes

For working with JSON response, you can use this library https://github.com/mikechambers/as3corelib

Add as3corelib to your project, then in the event handler instead of XML you can give

var response:Object = JSON.decode(e.target.data);

then you will be able to access other properties like response.property