0

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.

B. Desai
  • 16,414
  • 5
  • 26
  • 47

1 Answers1

1

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'];
B. Desai
  • 16,414
  • 5
  • 26
  • 47