2015-08-26 89 views
0

以下是我的代碼:爲什麼在以下情況下JSON數據沒有轉換爲數組?

$json_body = $application->request->getBody(); 
    /*echo "JSON Body : ".$json_body; 
    die; 
prints following data : 
JSON Body : 
{ 「current_user_id」:901 
    "user_id":990 
} 
*/ 

$request_data = json_decode($json_body, true); // Parse the JSON data to convert that into an assoc. array 
print_r($request_data); die;//This statement prints nothing 

我沒有得到爲什麼陣列notgetting執行該語句$request_data = json_decode($json_body, true);

請別人幫我後打印。

+2

'「'不等於'「'性格似乎無效你得到JSON'$應用程序 - >請求 - > getBody() ;' – MrRP

+0

做一個'var_dump($ json_body);'來檢查該變量的類型是否是一個字符串 – pythonian29033

回答

1

您的JSON字符串無效。缺少逗號和不等於"

有效的JSON:

{ 
    "current_user_id": 901, 
    "user_id": 990 
} 
1

它看起來像$application->request->getBody();方法是901值後會返回一個無效的JSON字符串

{ 「current_user_id」:901 
    "user_id":990 
} 

它缺少一個逗號(,),應該是這樣的:

{ 
    "current_user_id":901, 
    "user_id":990 
} 

而且,我不確定它是否相關,但可能不支持「current_user_id」上使用的引號: "不同

相關問題