2012-02-25 146 views
-1

发送卷曲-i -X POST -d 'JSON = { “金额”:1000, “idPlayers”:1}' http://www.myurl.com/updateamount.phpPHP不获取JSON值I从卷曲

我的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

奏效的感谢!我尝试过,但不正确! – 2012-02-25 22:12:31

+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']); – 2012-02-26 23:55:57