如何在Flash ActionScript 3.0中使用JSON API

bar*_*rit 0 flash json actionscript-3

我想知道是否有人可以解释或指出我如何实现在ActionScript 3.0中使用JSON的API.我特别想知道的是如何获取具体信息.以下是我在XML中的使用方法,但我不知道如何在JSON中执行类似于获取XML标记的等效内容.例如,使用twitter API,我想获取文本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();
        }
Run Code Online (Sandbox Code Playgroud)

-------新代码-----

公共函数onJSONLoaded(e:Event){

trace("onJSONLoaded()called");

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

        trace("json=" + json);
    } 
Run Code Online (Sandbox Code Playgroud)

它的踪迹是

onJSONLoaded()调用

json = [object Object]

Dio*_*ode 5

要使用JSON响应,您可以使用此库 https://github.com/mikechambers/as3corelib

将as3corelib添加到项目中,然后在事件处理程序中添加,而不是XML

var response:Object = JSON.decode(e.target.data);
Run Code Online (Sandbox Code Playgroud)

那么你将能够访问其他属性,如 response.property

  • 或者在Flash Player 11中使用[native JSON](http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/JSON.html)解析 (2认同)