简体   繁体   中英

How to receive json via POST in PHP using JsonObjectRequest in Android

I am new to PHP.

I am sending json using JsonObjectRequest in Android via POST Method.

I don't know how to retrieve that json in php and decode it. Could you help me? The json I am sending is

{"firstname":"test","lastname":"test"}

I need both the JSON objects in seperate variables.

You can get this data by file_get_contents("php://input"); . And then decode it by json_decode() . Try following code:

$data_json = file_get_contents("php://input");
$data = json_decode($data_json,true);
var_dump($data); //show your data

EDIT

To echo your data:

echo $data['firstname'];
echo $data['lastname'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM