用PHP接收JSON帖子我試圖在一個支付界面網站上收到一個JSON帖子,但我無法破解它。當我打印:echo $_POST;我得到:Array當我嘗試這個的時候,我什么也得不到:if ( $_POST ) {
foreach ( $_POST as $key => $value ) {
echo "llave: ".$key."- Valor:".$value."<br />";
}}當我嘗試這個的時候,我什么也得不到:$string = $_POST['operation'];$var = json_decode($string);echo $var;當我嘗試這樣做時,我會變成空:$data = json_decode( file_get_contents('php://input') );var_dump( $data->operation );當我這么做的時候:$data = json_decode(file_get_contents('php://input'), true);var_dump($data);我得到:NULLJSON格式是(根據支付站點文檔):{
"operacion": {
"tok": "[generated token]",
"shop_id": "12313",
"respuesta": "S",
"respuesta_details": "respuesta S",
"extended_respuesta_description": "respuesta extendida",
"moneda": "PYG",
"monto": "10100.00",
"authorization_number": "123456",
"ticket_number": "123456789123456",
"response_code": "00",
"response_description": "Transacción aprobada.",
"security_information": {
"customer_ip": "123.123.123.123",
"card_source": "I",
"card_country": "Croacia",
"version": "0.3",
"risk_index": "0"
}
}}付款網站日志顯示一切正常。有什么問題嗎?
4 回答
蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
$data = json_decode(file_get_contents('php://input'), true);print_r($data);echo $data["operacion"];編輯
echo file_get_contents('php://input');
慕后森
TA貢獻1802條經驗 獲得超5個贊
$_POST = json_decode(file_get_contents('php://input'), true);- 4 回答
- 0 關注
- 812 瀏覽
添加回答
舉報
0/150
提交
取消
