如何使用ActionScript 3.0发布的JSON数据?

编程入门 行业动态 更新时间:2024-10-27 14:30:10
本文介绍了如何使用ActionScript 3.0发布的JSON数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在ActionScript WebServices的工作。我发现下面的code,让我用只实现GET方法的JSON的URL。但是,它不为POST方法(甚至不进入的onComplete的方法)的工作。我搜索网,并未能找到任何答案。如何使用ActionScript 3.0我POSTJSON数据?

包 { 进口flash.display.Sprite; 进口flash.URLRequest; 进口flash.URLLoader; 进口flash.events *。 进口com.adobe.serialization.json.JSON; 公共类DataGrab扩展Sprite {     公共职能DataGrab(){     }     公共职能的init(资源:字符串):无效{             VAR装载机:的URLLoader =新的URLLoader();             VAR要求:的URLRequest =新的URLRequest(资源);             loader.addEventListener(引发Event.COMPLETE,的onComplete);             loader.load(要求);     }     私有函数的onComplete(五:事件):无效{             VAR装载机:的URLLoader =的URLLoader(e.target);             VAR jsonData:对象= JSON.de code(loader.data);             对于(VAR我:字符串中jsonData)             {                 迹第(i +:+ jsonData [I]);             }     } } }

解决方案

您需要指定您的URLRequest对象使用的方法。默认为GET。这可能是第二个参数给你的的init 方法:

公共职能的init(资源:字符串,方法:字符串=GET):无效{     VAR装载机:的URLLoader =新的URLLoader();     VAR要求:的URLRequest =新的URLRequest(资源);     request.method =方法;     loader.addEventListener(引发Event.COMPLETE,的onComplete);     loader.load(要求); }

当你调用这个函数,你可以使用静态 GET 和 POST 的 URLRequestMethod 而不仅仅是字符串传递额外的安全性的一点点。

I have to work with webservices in Actionscript. I found the following code that allows me to use JSON URLs that implement only the GET method. However, it doesn't work for POST methods (doesn't even enter the "onComplete" method). I searched the net and was unable to find any answers. How can i "POST" JSON data using Actionscript 3.0?

package { import flash.display.Sprite; import flash.URLRequest; import flash.URLLoader; import flash.events.*; import com.adobe.serialization.json.JSON; public class DataGrab extends Sprite { public function DataGrab() { } public function init(resource:String):void { var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest(resource); loader.addEventListener(Event.COMPLETE, onComplete); loader.load(request); } private function onComplete(e:Event):void { var loader:URLLoader = URLLoader(e.target); var jsonData:Object = JSON.decode(loader.data); for (var i:String in jsonData) { trace(i + ": " + jsonData[i]); } } } }

解决方案

You need to specify the method used with your URLRequest object. The default is GET. This could be a second argument to your init method:

public function init(resource:String,method:String = "GET"):void { var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest(resource); request.method = method; loader.addEventListener(Event.COMPLETE, onComplete); loader.load(request); }

When you call this function you can use the static GET and POST properties of URLRequestMethod rather than just passing strings for a little bit of extra safety.

更多推荐

如何使用ActionScript 3.0发布的JSON数据?

本文发布于:2023-11-15 15:07:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   数据   ActionScript   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!