Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
AS3从PHP读取JSON_Php_Json_Actionscript 3 - Fatal编程技术网

AS3从PHP读取JSON

AS3从PHP读取JSON,php,json,actionscript-3,Php,Json,Actionscript 3,我正在从php向actionscript发送json数据,但我收到了这个错误 SyntaxError: Error #1132: Entrada de análisis JSON no válida. at JSON$/parseCore() at JSON$/parse() at Code.GUI.Menu::Biblioteca/urlLoaderCompleteHandler() at flash.events::EventDispatcher/dispat

我正在从php向actionscript发送json数据,但我收到了这个错误

SyntaxError: Error #1132: Entrada de análisis JSON no válida.
    at JSON$/parseCore()
    at JSON$/parse()
    at Code.GUI.Menu::Biblioteca/urlLoaderCompleteHandler()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()
这是我的动作脚本代码

package Code.GUI.Menu
{   
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;

    public class Biblioteca extends MovieClip
    {
        var urlLoader:URLLoader=new URLLoader();

        public function Biblioteca () :void
        {
            addEventListener(Event.ADDED_TO_STAGE,init);
        }

        public function init(event:Event){
            urlLoader.load(new URLRequest("test.php"));
            urlLoader.addEventListener(Event.COMPLETE, urlLoaderCompleteHandler);
        }
        function urlLoaderCompleteHandler(e:Event):void {
            trace(e.target.data) ;
            var arrayReceived:Object = JSON.parse(e.target.data);
        }

    }

}
这是test.php

<?php 
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
header('Content-Type: application/json');
echo json_encode($arr);
?>
它起作用了!但actionscript似乎在sintax输出方面存在问题

Object {a: 1, b: 2, c: 3, d: 4, e: 5…}

修正!我需要添加本地主机url以便php处理它
urloader.load(新的URLRequest(“http://localhost:8888/test.php"));

已修复!我需要添加本地主机url,以便php处理它
urloader.load(新的URLRequest(“http://localhost:8888/test.php"));请将您的答案添加为正确答案并接受,以便其他人可以找到:)
$.getJSON('test.php',{format: "json"}, function(data) {
console.log(data);
});
Object {a: 1, b: 2, c: 3, d: 4, e: 5…}