AS3从PHP读取JSON
我正在从php向actionscript发送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
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…}