2012-02-25 3 views
-1

에서 보내는 JSON 값을 얻을하지 않습니다 컬 -i -X ​​POST는 -d 'JSON = { "금액": 1000 "idPlayers을": 1}'http://www.myurl.com/updateamount.phpPHP는 내가 컬

내 PHP 코드 :

<?php 

    $json = urldecode($_GET['jsonSendData']); 
    $json = str_replace("\\", "", $json); 
    $data = json_decode($json, true); 

// if i hard code it here it works fine, but need from a post from curl 
//$json = '{"Amount":1000,"idPlayers":1}'; 

    $data = json_decode($json, true); 

    echo "json = ", $json; 

    $amount = mysql_real_escape_string($data['Amount']); 
    $id = mysql_real_escape_string($data['idPlayers']); 

    echo "Amount = ",$amount; 
    return; 

답변

1

봅니다 포스트 데이터를 읽고 올바른 이름을 사용하도록 변경 :

$json = urldecode($_POST['json']); 
+0

이 덕분에 일이! 나는 일찍 게시물을했지만 올바르게하지 못했습니다! –

+0

내 Xcode 사람이 아래처럼 좋아할 수 있다고 생각하므로 'json'값을 보낼 필요가 없습니다. 하지만 어떤 아이디어도 효과가 없습니까? $ json = urldecode ($ _ POST [ 'json']); \t $ json = str_replace ("\\", "", $ json); \t $ data = json_decode ($ json, true); // $ amount = json_decode ($ _ POST [ 'Amount']); // $ player_id = json_decode ($ _ POST [ 'idPlayers']); –