2014-01-28 123 views
0

IM從PHP發送JSON數據來動作,但我得到這個錯誤AS3閱讀JSON從PHP

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); 
?> 

這是它的閃光cs6控制檯顯示

<?php 
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); 
header('Content-Type: application/json'); 
echo json_encode($arr); 
?> 
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() 

當我檢查與javascipt的

$.getJSON('test.php',{format: "json"}, function(data) { 
console.log(data); 
}); 

它的作品!但動作似乎有sintax輸出的問題

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

固定!我需要添加本地主機的URL爲了處理它'urlLoader.load(新的URLRequest(「http:// localhost:8888/test.php」));' –

+0

請添加您的答案作爲一個正確的答案和接受它,讓其他人可以找到它:) – Jono

回答

0

固定!我需要添加本地主機的網址,以便PHP來處理它 urlLoader.load(new URLRequest("http://localhost:8888/test.php"));