2010-12-02 159 views
0

我從我的Flash文件傳遞一個JSON編碼的數據到PHP我跟蹤使用螢火蟲的數據輸出,我看到它傳遞給PHP,但是當我嘗試通過PHP返回值返回到Flash我得到一個空字符串可以有一個expalin爲什麼PHP的行爲是這樣的?這裏是代碼Php數據丟失

<?php 

$data = urldecode(utf8_decode(stripslashes($_REQUEST['data']))); 

$decoded_result = json_decode($data); 

print_r($decoded_result); 
echo output.'='.$decoded_result; 

?> 

回答

4

你一個在output變量名$錯過?

想想吧,哪裏是$output變量名?甚至有一個?

此外,你調用json_decode,這JSON解碼成原生PHP對象,它不具有隱含的字符串表示,這將是怪異的,當你強迫它爲一個字符串,我認爲你的意思爲了輸出從data$_REQUEST散列解碼的JSON,將PHP對象返回給客戶端沒有用處。

也許你的意思是這樣:

<?php 

    $data = urldecode(utf8_decode(stripslashes($_REQUEST['data']))); 

    header('Content-type: application/json');  
    echo $data; //according to your logic, $data already contains JSON, so just output it. 

?> 
+0

取決於錯誤的設置,如果一個常量不存在名爲'output`將輸出發送到瀏覽器的內容,多數民衆贊成,所以很可能他更只是發送一個字符串。我想他也想`print_r` – RobertPitt 2010-12-02 20:56:25