Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Actionscripts 3使用内容类型定义获取/发布到服务器_Actionscript 3_Flash_Air_Animate Cc - Fatal编程技术网

Actionscript 3 Actionscripts 3使用内容类型定义获取/发布到服务器

Actionscript 3 Actionscripts 3使用内容类型定义获取/发布到服务器,actionscript-3,flash,air,animate-cc,Actionscript 3,Flash,Air,Animate Cc,我需要从/向服务器获取并发送请求。我在这个网站上找到了一个代码,但它不适合我。api url为true,我可以从firefox获取数据{out:355} import com.adobe.serialization.json.JSON; var request:URLRequest=new URLRequest(); request.url="******************************************" request.requestHeaders=[new URLR

我需要从/向服务器获取并发送请求。我在这个网站上找到了一个代码,但它不适合我。api url为true,我可以从firefox获取数据{out:355}

import com.adobe.serialization.json.JSON;

var request:URLRequest=new URLRequest();
request.url="******************************************"
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);

function receive(event:Event):void
{
    var myResults=JSON.decode(event.target.data);
    trace(myResults);
}
错误:

场景1,“主页”层第1帧第15行第25栏1061:调用 一种可能未定义的方法,通过静态 类型类

结果:

{out:352}


json.out=352

没有json.decode这是错误消息告诉您的。你为什么不直接读呢?JSON有两种方法Stringify和parse。为什么这个方法有效而我的方法无效?这个代码比Adobe文档代码简单。我假设你的代码不起作用,因为JSON已经是AS3的顶级,默认情况下会导入。所以,即使你导入旧的、不推荐的东西,默认情况下你仍然会使用新的东西。你是什么意思?你只需要换一行,其他的都保持不变。工作正常。如何发布数据?
import com.adobe.serialization.json.JSON;

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

function receive(event:Event):void
{
    trace(event.target.data);
    var json: Object = JSON.parse(event.target.data);
    trace("json.out = ", json.out);
}