在 Actionscript 中获取和解析 JSON [英] Get and parse JSON in Actionscript

查看:35
本文介绍了在 Actionscript 中获取和解析 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是向这个 URL 发出一个 get 请求:http://api.beatport.com/catalog/3/most-popular,它应该返回一些 JSON,然后从中解析出某些信息.

What I want to do is make a get request to this URL: http://api.beatport.com/catalog/3/most-popular, which should return some JSON and then parse out certain information from it.

我将如何在 Actionscript 3 中执行此操作?我更关心的是弄清楚如何将数据提供给 JSON 解析器而不是解析 JSON,因为似乎有很多关于解析 JSON 的问题.我想在 AS3 中这样做的原因是我有一个 3D flash 可视化设置,我想获取这些数据,解析出相关的位,然后在可视化中显示解析的位.

How would I go about doing this in Actionscript 3? I'm more concerned with figuring out how to get the data to feed to a JSON parser rather than parsing the JSON, since there seem to be plenty of questions about parsing JSON. The reason I want to do this in AS3 is that I have a 3D flash visualization set up and I want to get this data, parse out the relevant bits, and then display the parsed bits in the visualization.

如果有更简单的方法用另一种语言来实现,我愿意接受除 AS3 之外的任何其他可以轻松与 Flash 集成的方法.

I'm open to any other ways of doing this that can easily be integrated with Flash besides AS3 if there's an easier way to do it in another language.

推荐答案

  1. corelib.swc 添加到您的库路径中.

  1. Add the corelib.swc to your library path.

导入 JSON 库:import com.adobe.serialization.json.JSON;

使用如下代码调用您的服务:

Call your service with code something like this:

var request:URLRequest=new URLRequest();
request.url=YOUR_ENDPOINT
request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
request.method=URLRequestMethod.GET;
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE, receive);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
loader.addEventListener(IOErrorEvent.IO_ERROR, notFound);
loader.load(request);

protected function receive(event:Event):void
{
     var myResults:Array=JSON.decode(event.target.data);
}

  • 使用 JSON.decode(results) 解析结果.

    as3corelib 在这里维护:https://github.com/mikechambers/as3corelib#readme.

    as3corelib is maintained here: https://github.com/mikechambers/as3corelib#readme.

    这篇关于在 Actionscript 中获取和解析 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆