天天看點

PHP接收json格式的POST資料

{

  "mobile" : "186xxxxx853",
  "pwd"    :  "123",
   "sign"     : "6493c19c0f099c3c5d4907d139bd5e21",
   "userId"  : "123",
   "typename" : "黃金錢包"
}      
$content = file_get_contents('php://input');
$post    = json_decode($content, true);

$mobile = $post['mobile'];

注:json_decode  第二個參數,寫true就是數組,不寫就是對象
當$post是對象的時候取mobile的值      
$mobile = $post->mobile;